Shell脚本入门到实战
脚本格式 #!/bin/bash 开头(指定解析器)
创建Shell 脚本: helloworld
需求创建一个Shell 脚本,输出helloworld
操作 先创建 datas 文件夹 如何创建 helloworld.sh文件,并写入helloworld内容
touch helloworld.sh
vim helloworld.sh
进入后
#!bin/bash
echo "helloworld"
双引号后面加你要输出的内容。
执行方式:
第一种采取bash or sh+脚本的相对路径或者绝对路径选中脚本 并不需要修改脚本的权限
sh+ 脚本的相对路径
sh helloworld.sh (输出结果 helloworld)
sh +脚本的绝对路径 (eg:先pwd 获取你脚本的路径)
sh /root/datas/helloworld.sh
bash +脚本的相对路径
bash helloworld.sh