bash的位置变量和特殊变量
2015-10-14 18:30
363 查看
bash编程的知识点:位置变量和特殊变量
位置参数变量:
scirpt1.sh arg1 arg2 ...
$0 $1 $2 ... ${10} ...
$0: 即为文件本身
脚本注释:除第一行的shebang之外,任何以#开头的行都表示为注释信息,会被解释器忽略;
# information
特殊变量:
$#:位置参数变量的个数,
$@:位置参数列表
$*:位置参数列表
练习:写一个脚本,能接受一个参数,此参数为系统上的某文本文件路径;
(1) 显示此文件的总行数;
#!/bin/bash
filedir=$1
lines=`wc -l $filedir |cut -d ' ' -f 1`
echo "$filedir lines is :$lines"
位置参数变量:
scirpt1.sh arg1 arg2 ...
$0 $1 $2 ... ${10} ...
$0: 即为文件本身
脚本注释:除第一行的shebang之外,任何以#开头的行都表示为注释信息,会被解释器忽略;
# information
特殊变量:
$#:位置参数变量的个数,
$@:位置参数列表
$*:位置参数列表
练习:写一个脚本,能接受一个参数,此参数为系统上的某文本文件路径;
(1) 显示此文件的总行数;
#!/bin/bash
filedir=$1
lines=`wc -l $filedir |cut -d ' ' -f 1`
echo "$filedir lines is :$lines"
相关文章推荐
- bash中的算术运算
- bash文本查看及处理工具
- bash快捷键及输入输出重定向
- bash文件名统配
- Android系统 adb shell命令大全
- Working with Python subprocess - Shells, Processes, Streams, Pipes, Redirects
- eclipse移植cocos2dx工程报错:Program "bash" is not found in PATH
- shell的脚本循环处理
- 09-Windows Server 2012 R2 会话远程桌面-标准部署-使用PowerShell进行部署2-2
- 08-Windows Server 2012 R2 会话远程桌面-标准部署-使用PowerShell进行部署2-1
- shell控制流结构笔记
- linux Bash脚本基础符号总结 (一)
- Shell学习/基本Linux命令/文件与目录
- shell脚本报错:-bash: xxx: /bin/sh^M: bad interpreter: No such file or directory
- 让你提升命令行效率的 Bash 快捷键
- shell脚本之lnmp的搭建
- Shell编程关于函数要注意的几点
- exit(-1)或者return(-1)shell得到的退出码为什么是255
- shell三剑客之grep
- ansible 连接 windows (通过powershell)