[Shell] input parameters
Obtain the input parameters of the shell script and the obtained parameters.
#! /Bin/bash # title: testPT. sh # atuhor: orangleliu # date: 2014-08-08 # desc: enter two parameters and the second digit. Print them if they are correct, error prompt # ==================================#function Check #================== =========== Check () {if [$ #-ne 2] # charge params numthen echo "You must input two params" return 1 elseall = "$ @" # get all input valuesecd = 'echo $ all | awk '{print $2} ''expr 1 + $ secd>/dev/null 2> & 1if [$? -Eq 0] then echo "$ all" elseecho "Sorry age is a number" return 1 fifi }#============== ==# Function main () #========================== Main () {Check $1 $ 2if [$? -Eq 1] then exitfi} Main $1 $2
Execution result
[Orangle @ localhost shell] $ bash testPT. sh
You must input two params
[Orangle @ localhost shell] $ bash testPT. sh orangle 13
Orangle 13
[Orangle @ localhost shell] $ bash testPT. sh orangle lzz
Sorry age is a number
Tips:
There must be spaces on both sides of if, and the symbols in if must be
When copying a variable, = do not have spaces on both sides
Reference
This article is from the "orangleliu notebook" blog, please be sure to keep this http://blog.csdn.net/orangleliu/article/details/38449559