Variable+if+while

Source: Internet
Author: User

[[email protected] mybash]# vim.hello.sh #! /bin/sh# This isA example bash Scriptecho"Hello world! \ n"Echo"parameter num: $#"Echo"script ' s name is $"Echo"parameter 0: $"Echo"parameter 1: $"if[$#-ge1] # Note: square brackets [] within the description of the content must be left open before and after, or wrong. Then IDX=$1#将变量idx赋值为参数 $1, the declaration of a variable cannot have a space, that is, there is no space between the variable name and the equal sign. Elseidx=3#ifNo parameter1, let it bedefaultValue3. Fi while[$idx-GT0 ]  DoEcho"idx is $idx" Let"idx=idx-1"Sleep1Datedoneexit0

$# represents the number of arguments passed to a script or function
$ A indicates the file name of the current script
$n arguments passed to the script or function. N is a number that represents the first parameter, and the second argument is $
-GT the number to the left is greater than or equal to the number on the right, greater than true
-lt the number to the left is less than or equal to the number on the right, less than true

Variable+if+while

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.