Variable array in C Shell, shell variable array

Source: Internet
Author: User

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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.