Tag Archives: C language skills

Differences between shell script variable assignment and C language variable assignment

in C, you can occasionally see variable assignments as follows:

x1 = x2 = 1;

this means that the variable x1 is equal to the variable x2 is equal to 2, and the execution is the same thing as

x1 = 1;
x2 = 1;

but in shell script assignment, meaning is different, if the command line x1 = x2 = 1, then the expression means the variable x1 is equal to x2 = 1, where x2 = 1 this is a string as a whole, there is no x2 variable, the test is as follows:

xxxxxx@STB-240:~$ Test1=Test2=1
xxxxxx@STB-240:~$ 
xxxxxx@STB-240:~$ echo $Test1
Test2=1
xxxxxx@STB-240:~$ echo $Test2

xxxxxx@STB-240:~$ 
xxxxxx@STB-240:~$ 

note: under the shell, only the value before the first equals sign is a variable, followed by the value of the variable.