1、建立 ".sh" 文件,helloworld.sh
#!/bin/bash
echo Hello World!!!
2、修改文件的权限,使脚本具有执行权限
chmod 777 helloworld.sh
3、输入./helloworld.sh 即可运行文件
注意,一定要写成 ./helloworld.sh,而不是 helloworld.sh,运行其它二进制的程序也一样,直接写 helloworld.sh,linux 系统会去 PATH 里寻找有没有叫 helloworld.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 helloworld.sh 是会找不到命令的,要用 ./helloworld.sh 告诉系统说,就在当前目录找。
#!/bin/bash
# 执行一个PHP程序
cd /Users/xiao/php
php line_count.php
#!/bin/bash
# 打开微信,停止2秒,打开qq程序
open /Applications/WeChat.app
sleep 2s
open /Applications/QQ.app
# 打开QQ浏览器,并跳转到Python下载页面
open -a "/Applications/QQBrowser.app" https://www.python.org/downloads/
网友评论