Linux学习之shell编程二
2014-03-16 20:38
92 查看
shell script 的默认变量
$0,$1......
在shell脚本里面,执行的脚本文件名就是$0变量,$1就是脚本的第一个参数。还有一些特殊的变量,比如:
$#:代表后接的参数个数
$@:代表$1,$2,$3,$4之意
$*:代表“$1c$2c$3c$4”,其中c为分隔符,默认为空格
shift:可以偏移变量号码,比如shift ,或者shift 2可以将变量代码向左移动1次或2次
得到结果:
$0,$1......
在shell脚本里面,执行的脚本文件名就是$0变量,$1就是脚本的第一个参数。还有一些特殊的变量,比如:
$#:代表后接的参数个数
$@:代表$1,$2,$3,$4之意
$*:代表“$1c$2c$3c$4”,其中c为分隔符,默认为空格
shift:可以偏移变量号码,比如shift ,或者shift 2可以将变量代码向左移动1次或2次
#!/bin/bash #filename:shell05.sh echo "The number of variables is ==> $#" echo "The total variable is ==> '$@'" echo "The first variable is ==> $1" shift #偏移一次 echo "The number of variables is ==> $#" echo "The total variable is ==> '$@'" echo "The first variable is ==> $1"运行./shell05.sh one two three four
得到结果:
The number of variables is ==> 4 The total variable is ==> 'one two three four' The first variable is ==> one The number of variables is ==> 3 The total variable is ==> 'two three four' The first variable is ==> two
相关文章推荐
- 【Linux入门学习之】vi/vim编辑器必知必会
- linux route命令学习
- tcpdump命令---Linux学习笔记
- Zynq-Linux移植学习笔记之十-u-boot网络配置
- 转顶嵌欧老师:深入学习嵌入式linux知识要点
- Linux_学习笔记_0
- linux学习
- LINUX驱动学习:加载模块时出现Device or resource busy的解决方法
- Linux 20150830学习整理 VIM、FIND、bash环境、特殊权限
- 给学习Linux系统小白的两三个建议
- linux学习第十九篇:压缩介绍,gzip,bzip2,xz压缩工具
- Linux学习笔记——磁盘管理命令
- linux下vi编辑器学习笔记
- 技术宅学习Linux系统还是很有前途的
- Linux学习基础教程
- Linux 学习:文件特殊权限SUID, SGID, SBIT
- linux学习入门10——linux文件系統挂载管理(linuxcast.net)(mount、umount、配置fstab进行自动挂载)
- Linux学习笔记:Linux文件系统上的特殊权限
- Linux学习记录—进程相关
- 写得蛮好的linux学习笔记