您现在的位置是:网站首页> 编程资料编程资料
Shell脚本中的位置变量参数(特殊字符)实例讲解_linux shell_
2023-05-26
353人已围观
简介 Shell脚本中的位置变量参数(特殊字符)实例讲解_linux shell_
$# : 传递到脚本的参数个数
$* : 以一个单字符串显示所有向脚本传递的参数。与位置变量不同,此选项参数可超过 9个
$$ : 脚本运行的当前进程 ID号
$! : 后台运行的最后一个进程的进程 ID号
$@ : 与$#相同,但是使用时加引号,并在引号中返回每个参数
$- : 显示shell使用的当前选项,与 set命令功能相同
$? : 显示最后命令的退出状态。 0表示没有错误,其他任何值表明有错误。
#!/bin/sh
#param.sh
# $0:文件完整路径名
echo "path of script : $0"
# 利用basename命令文件路径获取文件名
echo "name of script : $(basename $0)"
# $1:参数1
echo "parameter 1 : $1"
# $2:参数2
echo "parameter 2 : $2"
# $3:参数3
echo "parameter 3 : $3"
# $4:参数4
echo "parameter 4 : $4"
# $5:参数5
echo "parameter 5 : $5"
# $#:传递到脚本的参数个数
echo "The number of arguments passed : $#"
# $*:显示所有参数内容i
echo "Show all arguments : $*"
# $:脚本当前运行的ID号
echo "Process ID : $"
# $?:回传码
echo "errors : $?"
输入./param.sh hello world
[firefox@fire Shell]$ ./param.sh hello world
path of script : ./param.sh
name of script : param.sh
parameter 1 : hello
parameter 2 : world
parameter 3 :
parameter 4 :
parameter 5 :
The number of arguments passed : 2
Show all arguments : hello world
Process ID : 5181
errors : 0
相关内容
- Shell脚本传递参数的3种方法比较_linux shell_
- Shell脚本传参数方法总结_linux shell_
- Shell中的变量使用小结_linux shell_
- Shell常用操作符总结_linux shell_
- Shell中的for和while循环详细总结_linux shell_
- Shell中的for循环总结_linux shell_
- Shell脚本bash: ./t.sh:/bin/bash^M:损坏的解释器: 没有那个文件或目录_linux shell_
- Shell脚本计算字符串长度和判断字符串为空小技巧_linux shell_
- Shell、Perl、Python、PHP访问 MySQL 数据库代码实例_linux shell_
- Bash脚本内置的调试方法技巧_linux shell_
