Execute script parameter acquisition in Linux

Source: Internet
Author: User

Linux variable $[#,@,0,1,2,*,$,?] Meaning

$# 是传给脚本的参数个数

$ 0 是脚本本身的名字 $ 1 是传递给该shell脚本的第一个参数 $ 2 是传递给该shell脚本的第二个参数 [email protected] 是传给脚本的所有参数的列表 $* 是以一个单字符串显示所有向脚本传递的参数,与位置变量不同,参数可超过 9 $$ 是脚本运行的当前进程ID号 $? 是显示最后命令的退出状态, 0 表示没有错误,其他表示有错误

Difference: [email protected], $*

Same point: All parameters are referenced
Differences: $* and [email protected] All represent all parameters passed to a function or script, and are not enclosed by double quotation marks (""), with "$" "$" ... All parameters are output in the form "$n". But when they are enclosed in double quotation marks (""), "$*" takes all the parameters as a whole and outputs all parameters in the form of "$ $ ... $n"; "[email protected]" separates the various parameters to "$" "$" ... All parameters are output in the form "$n".

$* and [email protected] detailed differences please see here

#!/bin/BashEcho "-----------------" forKeyinch "[email protected]" Do    Echo '[email protected]'$key DoneEcho "-----------------------------" forKey2inch$* Do    Echo '$*'$key 2 Done1, quoted execution and results: [[email protected]~]# Bashfile.SHLinux "python C" -----------------[email protected] linux[email protected] python c-----------------------------$*linux$*python$*C2, without quotes execution and results: [[email protected]~]# Bashfile.SHLinux python c-----------------[email protected] linux[email protected] python[email protected] C-----------------------------$*linux$*python$* C

Execute script parameter acquisition in Linux

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.