Shell Common syntax

Source: Internet
Author: User

#!/bin/bash
echo "**********argument**********"
Echo Script Name: $
Echo First argument $
echo second argument
echo num of argument $#
echo all argument [email protected]

#function
Equal ()
{
Case $ in
$)
return 0
;;
*)
Return 1
;;
Esac
}

#if
echo "**********test if**********"
if equal $;
Then
echo "Equal"
Else
echo "Not Equal"
Fi

If [$#-gt 0];
Then
echo number of argument greater than 0
echo [email protected]
Else
echo number of argument is 0
Fi

#for
echo "**********test for**********"
For i in [email protected]
Do
Echo $i
Done
Limit=5
for ((a=1; a<= $LIMIT; a++))
Do
echo "$a"
Done

#while
echo "**********test while**********"
A=0
limit=10
While [$a-lt $LIMIT]
Do
Echo $a
a=$ ((a+1))
Done

#case
echo "**********test case**********"
Read-p "Press some key, then press RETURN:" Key
Case $KEY in
[A-za-z])
echo "It ' s a letter!"
;;
[0-9])
echo "It ' s a number!"
;;
*)
echo "Other key!"
;;
Esac

#printf
echo "**********test printf**********"
X=ABC; printf "X is now:%s, Enter new value:" $x; Read X

Run./test.sh 1 1 results are as follows:

Shell Common syntax

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.