######1.使用vim编辑器创建一个test.sh shell脚本
[webuser@xx-xx-xx-xx ~]$ vim test.sh
######2.在脚本第一行中输入如下脚本
#!/bin/bash
echo "Hello World !"
说明:#!是一个约定标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种Shell;
######3.给脚本test.sh授予可执行权限
chmod +x ./test.sh
######4.执行脚本
[webuser@xx-xx-xx-xx ~]$ ./test.sh
hello world
#####5.echo命令用于字符串输出
echo 'hello world' ##单引号
echo "hello world" ##双引号
echo hello world ##省略双引号
echo "\"hello world\"" ##转义符输出
输出结果是:
[webuser@xx-xx-xx-xx ~]$ ./test.sh
hello world
hello world
hello world
"hello world"
######6.read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量
#!/bin/bash
read name
echo "$name is a good student"
输出结果是:
[webuser@xx-xx-xx-xx ~]$ ./test.sh
lili
lili is a good student
######7.将打印结果输出到文件中
#!/bin/bash
readname
echo "$name is a good status" > myfile
######8.获取字符串的长度
usernam="lili"
echo ${#usernam} #输出4
######9.查看目录下的所有文件
for file in $(ls *)
do
echo $file
done