Is there a difference between using a set in ksh to easily set a variable?

Are the following two lines completely equivalent? If not what difference? I saw that many shell scripts use number 1 and it’s just interesting what this gives you compared to number 2.

  • typeset TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties"
  • TARGET="${XMS_HOME}/common/jxb/config/${RUNGROUP}.${ENV}.properties"
+4
source share
2 answers

typeset will create a local variable (which does not "flow"). This is useful in functions, but I also saw that it is used at the top level of the shell script.

 a=0 function x { typeset a=1 } x echo $a function y { a=2 } y echo $a 

will print

 0 2 

You can also use typeset to create arrays and integers.

[EDIT] The function keyword has been added because it requires some shells. Remove it if it offends your shell, but it should work with most versions.

+4
source

since the shell script is a freely typed language (in which the variables do not have a datotype), we can use a set of types to set a specific variable only to get the same data type of values.

0
source

Source: https://habr.com/ru/post/1286576/


All Articles