Shell note variables

Source: Internet
Author: User
Shell note variable Shell code #! /Bin/bash # line comment at the beginning # The first line of the shell script is generally #! /Bin/bash indicates that/bin/bash is responsible for interpreting www.2cto.com # defining the variable str & quot; stringvalue & quot; num123echostris :...
Shell note variable Shell code #! /Bin/bash # line comment at the beginning # The first line of the shell script is generally #! /Bin/bash indicates that/bin/bash is responsible for interpreting www.2cto.com # defining the variable str = "string value" num = 123 echo str is: \ "$ str \" echo num \'s value is: $ num # Note: #1. "=" There are no spaces on both sides. any spaces may cause errors. #2. although quotation marks can be omitted when defining a word, quotation marks are required when defining more than one variable value (including spaces or tabs. #3. although double quotation marks can be used, errors may occur. Use single quotes to disable extended bash features www.2cto.com # Parameter variables (extended with single quotes) #$0 indicates the command itself to be executed, so the script is env. sh #$1 indicates the first parameter, $2 indicates the second parameter, and so on; # $ @ indicates that all variables are referenced at a time, it is extended to all command line parameters separated by spaces; #$ # indicates the number of variables passed to the script; echo '$0 is' $0 echo '$1 is' $1 echo '$2 is' $2 echo '$3 is' $3 echo '$ # is' $ # echo '$ @ is' $ @ # environment variable, use the export command to set and unset export editor = vim unset editor # variable default value # $ {parameter:-word}. if parameter is not set or is empty, then shell expands the word and replaces the result. The parameter value is not changed. # $ {Parameter: = word} if parameter is not set or is empty, shell expands word and assigns the result to parameter. This value is then replaced. Location parameters or special parameter values cannot be assigned in this way. # $ {Parameter :? Word} if parameter is not set or is empty, shell expands the word and writes the result to a standard error. If no word exists, a message is written. If the shell is not interactive, the extension exists. # $ {Parameter: + word} if parameter is not set or is empty, www.2cto.com unset x y = "abc def" echo "/$ {x: -'XYZ'}/$ {y:-'XYZ'}/$ x/$ y/"unset x y =" abc def "echo"/$ {x: = 'XYZ'}/$ {y:-'XYZ'}/$ x/$ y /"

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.