Assume we have a variable 'a' set to 12345 :
set a 12345
Now how do i set a new variable 'b' which contains the value of 'a' and another string say 9876
workaround is something like
set a "12345" set u "9876" set b $a$u
but i dont want to specify $u
instead i want the direct string to used..
In JavaScript, we can assign strings to a variable and use concatenation to combine the variable to another string. To concatenate a string, you add a plus sign+ between the strings or string variables you want to connect. let myPet = 'seahorse'; console.
Append all of the value arguments to the current value of variable varName. If varName doesn't exist, it is given a value equal to the concatenation of all the value arguments. This command provides an efficient way to build up long variables incrementally.
The append command has a different semantics: you pass a variable name as first argument, and a variable list of values as other arguments. I edited your answer changing that: you must use $string1 and $string2 to access the values of the two variables and put the variable name you want to write to.
The concat command joins each of its arguments together with spaces after first trimming all leading and trailing whitespace, and in the case of a list, the results will be flattened. Although this command will concatenate any arguments provided, we will be focusing on its usage as it applies to the list elements.
You can do:
set b ${a}9876
or, assuming b
is either set to the empty string or not defined:
append b $a 9876
The call to append
is more efficient when $a
is long (see append
doc).
other option is to use set command. since set a gives value of a we can use it to set value of b like below
set b [set a]9876
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With