Shell script 的默认变量($0, $1...)
来源:互联网 发布:取消windows启动管理器 编辑:程序博客网 时间:2024/06/05 11:49
假设我要运行一个可以携带参数的 script ,运行该脚本后萤幕会显示如下的数据:
- 程序的档名为何?
- 共有几个参数?
- 若参数的个数小於 2 则告知使用者参数数量太少
- 全部的参数内容为何?
- 第一个参数为何?
- 第二个参数为何
#!/bin/bash
#The program shows the script name,and the parameters....
echo "The script name is ==> $0"
echo "The num of the parameters is ==>$#"
[ $# -lt 2 ] && echo "The num is less than 2. Stop here!" && exit 0
echo "The whole parameter is ==> '$@'"
echo "The 1st parameter is ==>$1"
echo "The 2nd parameter is >$2"
执行脚本:
[oracle@SOR_SYS~]$ sh parameters.sh opt1 oracle 192.168.50.229 8081
The script name is ==> parameters.sh
The num of the parameters is ==>4
The whole parameter is ==> 'opt1 oracle 192.168.50.229 8081'
The 1st parameter is ==>opt1
The 2nd parameter is >oracle
[oracle@SOR_SYS~]$
- $# :代表后接的参数『个数』,以上表为例这里显示为『 4 』;
- $@ :代表『 "$1" "$2" "$3" "$4" 』之意,每个变量是独立的(用双引号括起来);
- $* :代表『 "$1c$2c$3c$4" 』,其中c 为分隔字节,默认为空白键, 所以本例中代表『 "$1 $2 $3 $4" 』之意。
- Shell script 的默认变量($0, $1...)
- Linux学习-shell script 的默认变量
- 连载shell(二):test判断,判断符号[ ],shell script的默认变量($0, $1...),shift参数变量偏移
- shell script 的默认参数($0,$1...)
- Shell script 的默认变数(`$0, $1`...)等
- Shell script 传参数处理(默认变量)
- Shell Script ----变量
- Shell script 的預設變數($0, $1...)
- Shell Script两个变量相乘
- shell 默认变量问题
- Shell Script 的学习
- shell script的debug
- shell script 的执行
- 【Unix/Linux.Shell Script】变量,运算符,$(())
- Shell Script介绍及变量使用
- 【shell script】变量及其相关操作
- shell脚本中的$默认变量
- shell script学习(二) shell中的变量说明
- 当我已成为大叔,CSDN成了床上等你
- 沃尔玛入股1号店交易完成 已开始业务对接
- SQL语句
- 使用递归高斯滤波器实现快速高斯模糊
- Mysql数据库双机热备份技术文档
- Shell script 的默认变量($0, $1...)
- 函数对象 (Function Objects)
- java读取Oracle值,不显示0
- 内核和用户空间共享内存的实现例程-proc和mmap
- VC 定时自动关闭MessageBox弹出对话框
- 字符,字节和编码
- JMS中的DeliveryMode和DurableSubscriber以及在activeMQ中的小BUG
- flex 教程参考
- Function Run Fun