1.首先在windos下,新建一个txt文件,
2,编写脚本
#!/bin/bash
# 编写hello world脚本
echo "Hello World!"
3.将.txt后缀改成.sh
4.上传到Linux
5,执行,
./hello.sh
6.若显示权限不足,赋予权限
chmod 777 ./hello.sh
7.若是 报错 坏的解释器: 没有那个文件或目录 的解决方法
sed 's/\r//' -i hello.sh
原因:
由于windows系统下换行符为 \r\n,linux下换行符为 \n,所以导致在windows下编写的文件会比linux下多回车符号 \r。
解决方法:
只需要去掉多余的 \r 回车符 即可。操作办法可以用sed命令进行全局替换