Linux case and function location parameters

Source: Internet
Author: User

 

 

Location parameters

$0, $1, $2, and so on...
Location parameter, which is passed to the script from the command line, to the function, or to a variable.
(For details, see Example 4-5 and example 11-15)
$ #
Number of command lines or location parameters (see example 33-2)
$ *
All location parameters are used as a word.
Note: "$ *" must be referenced.
$ @
It is synonymous with $ *, but each parameter is an independent "" reference string, which means that the parameter is completely passed,
It is not interpreted and extended. This also means that each parameter in each parameter list is treated as an independent
Word.
Note: "$ @" must be referenced.

 

 

 

For details, see the code:

#! /Bin/bash
# Arglist. Sh

E_badargs = 65

If [! -N "$1"]
Then
Echo "Usage: 'basename $ 0' argument1 argument2 etc ."
Exit $ E_BADARGS
Fi

Echo

Index = 1

Echo "Listing args with \" \ $ *\":"
For arg in "$ *"
Do
Echo "Arg # $ index = $ arg"
Let "index + = 1"
Done
Echo "Entire arg list seen as single word ."

Echo

Index = 1

Echo "Listing args with \" \$ @\":"
For arg in "$ @"
Do
Echo "Arg # $ index = $ arg"
Let "index + = 1"
Done
Echo "Arg list seen as separate words ."

Echo

Index = 1

Echo "Listing args with \ $ * (unquoted ):"
For arg in $ *
Do
Echo "Arg # $ index = $ arg"
Let "index + = 1"
Done
Echo "Arg list seen as separate words ."

Exit 0

 

#! /Bin/bash
Echo 'in in work'
Binhome = 'dirname $0'
Echo $ binhome
CD $ binhome
Binhome = 'pwd'
Echo $ binhome

WorkHome =$ {binHome }/..
Echo $ workHome
B =$ {workHome}/common/date. sh
Echo $ B
Source $ {workHome}/common/date. sh
Index = 1
For arg in $ *
Do
If [["x $ arg" = "x"]; then
Exit 1
Else
Case $ index in
1)
LoadDate = $ arg
;;
2)
Days = $ arg
;;
*)
ExecFile = $ arg
ExecDate =$ {loadDate}
For (I = 0; I <days; I = I + 1 ))
Do
Bash $ {execFile }$ {execDate}
ExecDate = 'dashdateadd $ {execDate} '1''
Done
;;
Esac
Let "index + = 1"
Fi
Done
Exit 0

 

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.