Shell Basic usage

Source: Internet
Author: User

#!/bin/bash #使用哪个shell执行echo "Hello World" username= "Tom" echo $username #chmod +x./test.sh settings can perform file #for loop output for skill in Ada coffe Action Java; Do echo "I am good at ${skill}script" Done#for file in ' ls/etc '; Do#echo "This is Name" ${file} #done # read-only variable readonly usernameusername= "STEVN" echo $username; #充值变量unset username# Intercept string string= "Alibaba is a great company" Echo ${string:4:9}array_name= (value0 value1 value2 value3) #数组元素echo ${array_ NAME[1]} #全部元素echo ${array_name[@]} #数组长度echo ${#array_name [@]}echo ${#array_name [*]} #数组其中一个元素长度echo ${#array_name [3 ]} #参数传递echo "parameter value is:" Echo echo $ echo $# echo $* echo $$ echo $!  echo [email protected] echo $-echo $? #运算val = ' Expr 2 + 2 ' echo ' two sum as: $val ' echo ' expr 2-5 ' echo ' expr 2\*5 ' echo ' expr 2%5 ' echo ' Expr 2/5 ' a=2b=2if [$a = = $b]thenecho "a==b" Elseecho "a!=b" fi if [$a-eq $b]thenecho "1" Elseecho "2" Fiecho "This is a test file" >test1.lua# Current date echo ' Date ' #按照格式打印printf "%-10s%-8s%-4s\n" name sex weight kg printf "%-10s%-8s%-4.2f \ n "Guo Jing male 66.1234 printf "%-10s%-8s%-4.2f\n" Yang over male 48.6543 printf "%-10s%-8s%-4.2f\n" Guo Fu 47.9876 #test判断num1 =100num2=100if test $[NUM1]- EQ $[num2]then echo ' The numbers is equal! ' else echo ' The numbers is not equal! ' fi# file to determine if test-e./bashthen Echo ' The file already exists! ' else echo ' The file does not exists! ' fi# written as a line (for a terminal command prompt) if [$ (ps-ef | grep-c "SSH")-gt 1]; Then echo "true"; Fifor Loop in 1 2 3 4 5do echo "The value was: $loop" donefor str in ' This is a string ' do echo $strdoneint =1while ($i nt<=5) do echo $int let "int++" Done#echo ' press <CTRL-D> exit ' #echo-n ' Enter your favorite movie name: ' #while read film#d o# echo "Yes!    $FILM is a good movie "#donefunWithReturn () {echo" This function adds the two numbers you enter ... "echo" enters the first number: "Read Anum echo" Enter the second number: "    Read Anothernum echo "two numbers for $aNum and $anotherNum!" Return $ (($aNum + $anotherNum))}funwithreturnecho "The sum of the two numbers entered is $?!"    Funwithparam () {echo "the first parameter is $!"    echo "The second parameter is $!"    echo "The tenth parameter is $ A!" echo "The tenth Oneparameter is ${10}! "    echo "11th parameter is ${11}!"    echo "The total number of parameters is $#!" echo "Output all parameters as a string $*!"} Funwithparam 1 2 3 4 5 6 7 8 9 34 73# contains the file source filename or. Filenameecho "test= ' 1223333 '" >./test1.luasource./test1.luaecho $test

  

Shell Basic usage

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.