Variable array in C Shell, shell variable array
Today I was just reading a bit of C Shell Content and found a very interesting thing! Environment variables can be set like arrays! The specific setting syntax is as follows:
Set variable = (element1 element2...) // note that elements are separated by spaces.
For example, if I run the set var = (123 def hij) Statement in C Shell, it indicates that an array of variables is set, where var [1] is 123, var [2] is def! It is strange that the array does not start from 0. var [0] is an empty string! Maybe this var [0] represents a special meaning like argv [0] of the C main function. I haven't understood this yet! If you know something, give me some advice !, The running result is as follows:
If you want to change the content of this variable array, It is very simple, similar to the change method in the array! For example, if you want to change the value of var [1] to abc, you only need to run a set var [1] = abc, as shown in:
What if I want to get the length of this array? With one #, you can easily get it! Take the example above for details! I want to get the length of the var variable array, as long as one
Echo $ # var // obtain the length of the variable array
Shows the running result:
OK. This is the variable array in C Shell that I have learned!