linux中的命令在shell脚本中怎么写

如题所述

#!/bin/bash
eval "cd /export/songhongwei/code"
eval "cd /export/songhongwei/data"
echo "上面两行就是在.shell书写linux命令的方式"

备注:

语法:eval cmdLine

eval会对后面的cmdLine进行两遍扫描,如果第一遍扫描后,cmdLine是个普通命令,则执行此命令;如果cmdLine中含有变量的间接引用,则保证间接引用的语义。

Shell 的 echo 指令与 PHP 的 echo 指令类似,都是用于字符串的输出。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-03-25
执行“nano function.sh”命令,创建新的shell脚本文件,名字为“function.sh”。

编辑新创建的shell脚本文件“function.sh"。函数必须先定义后使用。

shell脚本的内容如下:
#!/bin/bash
add(){

sum_1=$1;
sum_2=$2;
sum=`expr $sum_1 + $sum_2`;
echo "the sum is ${sum}";
}

add $1 $2

4
给新创建的function.sh赋可执行权限,命令为“chmod 755 function.sh”。

5
使用“./function.sh 1 2”调用脚本,并给脚本传递两个数字。

6
执行命令的结果为“the sum is 3”。本回答被提问者采纳
相似回答