Skip to content

Instantly share code, notes, and snippets.

@windard

windard/args.sh

Created Mar 30, 2020
Embed
What would you like to do?
args.sh
#!/bin/bash
#
msg1='$'
echo "Shell本身的PID(ProcessID)"
printf "The ${msg1}$ is %s\n" "$$"
echo "Shell最后运行的后台Process的PID"
printf "The ${msg1}! is %s\n" "$!"
echo "最后运行的命令的结束代码(返回值)"
printf "The ${msg1}? is %s\n" "$?"
echo "使用Set命令设定的Flag一览 "
printf "The ${msg1}- is %s\n" "$-"
echo
echo "参数相关,直接运行脚本 ./args.sh 或者 sh args.sh 结果一致"
echo '所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。 '
printf "The ${msg1}* is %s\n" "$*"
echo '所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。'
printf "The ${msg1}@ is %s\n" "$@"
echo "添加到Shell的参数个数 "
printf "The ${msg1}# is %s\n" "$#"
echo "Shell本身的文件名 "
printf "The ${msg1}0 is %s\n" "$0"
echo "shell 第一个参数"
printf "The ${msg1}1 is %s\n" "$1"
echo "shell 第二个参数"
printf "The ${msg1}2 is %s\n" "$2"
@windard

This comment has been minimized.

Copy link
Owner Author

@windard windard commented Mar 30, 2020

(byted)  $ sh args.sh 1243 245451 46252323
Shell本身的PID(ProcessID)
The $$ is 14841
Shell最后运行的后台Process的PID
The $! is
最后运行的命令的结束代码(返回值)
The $? is 0
使用Set命令设定的Flag一览
The $- is hB

参数相关,直接运行脚本 ./args.sh 或者 sh args.sh 结果一致
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。
The $* is 1243 245451 46252323
所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。
The $@ is 1243
The $@ is 245451
The $@ is 46252323
添加到Shell的参数个数
The $# is 3
Shell本身的文件名
The $0 is args.sh
shell 第一个参数
The $1 is 1243
shell 第二个参数
The $2 is 245451
(byted)  $
(byted)  $
(byted)  $
(byted)  $ ./args.sh 123 134341ascsd 434523
Shell本身的PID(ProcessID)
The $$ is 14902
Shell最后运行的后台Process的PID
The $! is
最后运行的命令的结束代码(返回值)
The $? is 0
使用Set命令设定的Flag一览
The $- is hB

参数相关,直接运行脚本 ./args.sh 或者 sh args.sh 结果一致
所有参数列表。如"$*"用「"」括起来的情况、以"$1 $2 … $n"的形式输出所有参数。
The $* is 123 134341ascsd 434523
所有参数列表。如"$@"用「"」括起来的情况、以"$1" "$2" … "$n" 的形式输出所有参数。
The $@ is 123
The $@ is 134341ascsd
The $@ is 434523
添加到Shell的参数个数
The $# is 3
Shell本身的文件名
The $0 is ./args.sh
shell 第一个参数
The $1 is 123
shell 第二个参数
The $2 is 134341ascsd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.