Linux Shell 编程参考文档
1-9 在 Shell 脚本中调用其他脚本
?? Shell 脚本的调用
在 Shell 脚本的执行过程中,Shell 脚本支持调用另一个 Shell 脚本,调用的格式为: 程序名
(1)调用 test20
实例 1-20:在 Shell 脚本 test19 中调用 test20。
#test19 脚本 #!/bin/sh
echo “The main name is $0” ./test20
echo “The first string is $1” #test20 脚本 #!/bin/sh
echo “How are you $USER?” (2)设置权限
[root@localhost bin]#chmod +x test19 [root@localhost bin]#chmod +x test20 (3)执行
[root@localhost bin]#./ test19 abc123 The main name is ./test19 How are you root?
the first string is abc123
编辑中命令区分大小写字符。 1)在 Linux
注意:
2)在 Shell 语句中加入必要的注释,以便以后查询和维护,注释以#开头。 3)对 Shell 变量进行数字运算时,使用乘法符号“*”时,要用转义字符“\\”进行转义。
4)由于 Shell 对命令中多余的空格不进行任何处理,因此程序员可以利用这一特性调整程序缩 进,达到增强程序可读性效果。
5)在对函数命名时最好能使用有含义且能容易理解的名字,即使函数名能够比较准确地表达函 数所完成的任务。同时建议对于较大的程序要建立函数名和变量命名对照表。
Linux Shell编程 第22页/共26页