linux shell脚本案例一

时间:2022-05-05 04:26:20

1.编写shell脚本内容: bsh1.sh文件

#!/bin/bash
echo "hello,ljf"
echo "what is your name?"
read p
echo "my name is ${p}"

2.执行脚本

chmod +x ./bsh1.sh

sh ./bsh1.sh

或者 ./bsh1.sh

3.执行结果:

[jurf@ljf-centos ljfshell1113]$ ./bsh1.sh
hello,ljf
what is your name?
l
my name is l
[jurf@ljf-centos ljfshell1113]$ sh ./bsh1.sh
hello,ljf
what is your name?
fu
my name is fu

“#!” 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行。

read命令是从 stdin 获取输入并赋值给 P 变量,最后在 stdout 上输出。