[Shell] input parameters

Source: Internet
Author: User

[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

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.