shell参数的输入与运用
来源:互联网 发布:网络借贷陷阱 编辑:程序博客网 时间:2024/06/05 09:46
在shell中参数的传递,也就是参数的输入使用$n
的格式进行输入。
$n
,其中,n代表数字,1就是在执行脚本时输入的第一个参数,2就是在执行脚本时输入的第一个参数,以此类推。
#!/bin/bash#Filename: Day02.sh#Introduction:It's file is to learning the basic knowledge of shell echo "Output"echo "The file name: $0"echo "The first parameter: $1"echo "The second parameter: $1"echo "The number of paramter is $#"
leeguo@leeguo-PC:~/Nutstore/Shell_code$ bash Day02.sh 1 2OutputThe file name: Day02.shThe first parameter: 1The second of paramter is 2
这个符号$
,除了参数的传输外,还有其他的功能。
-
- $*:以字符串的形式显示所有输入的参数,引号"$*"
是一一个字符串的形式输出形式进行输出
- $@:和上面"$*"
的功能基本相同,都是在引号"$@"
是一单个的输出形式进行输出
- $$:该脚本进程的ID号
- $?:脚本在运行完成后,退出的状态,若为0则说明没有错误
#!/bin/bash#Filename: Day02.sh#Introduction:It's file is to learning the basic knowledge of shell echo "$*"echo "$@"for target in "$*";do echo $targetdonefor target in "$@";do echo $targetdone
运行的结果:
leeguo@leeguo-PC:~/Nutstore/Shell_code$ bash Day02.sh 1 2 3# The output of $*1 2 3# The output of $@1 2 3# --------1 2 3# --------123
本文参考:http://www.runoob.com/linux/linux-shell-passing-arguments.html
阅读全文
0 0
- shell参数的输入与运用
- 判断Shell程序输入参数的个数
- 判断Shell程序输入参数的个数
- 判断Shell程序输入参数的个数
- shell判断输入的参数是不是数字
- 判断Shell程序输入参数的个数
- shell的输入与输出
- shell的输入与输出
- 不定参数函数的运用与实现
- 交互式输入shell参数
- 【shell学习】输入参数
- shell 脚本 输入参数 学习
- Linux shell 逆序输出输入的参数
- 最简单的shell输入参数语句demo--getopts
- shell 脚本中关于用户输入参数的处理
- Shell脚本中判断输入参数个数的方法
- linux shell脚本读取用户输入的参数
- linux shell脚本读取用户输入的参数
- Android 如何做到隐藏手机底部虚拟按键?
- 006_HTTP_GET_POST
- yilide huawei gongzuo
- 软件工程第五次实验
- 三子棋
- shell参数的输入与运用
- ligerUI中ligerGrid的简易用法
- 多线程题例
- cocos2dx控件-----ListView的使用(label自动换行)
- day02-Linux的文件系统(目录树)
- 二叉树的层次遍历及求节点个数的算法
- python itertools的函数(含有排列组合函数)
- 公安综合指挥可视化系统首次亮相深圳安博会
- linux复制粘贴命令