Skip to content

🐚 Shell 编程

Shell 脚本能够将复杂的命令序列化、自动化。

基础语法

变量

bash
NAME="Linux"
echo "Hello $NAME"

条件语句

bash
if [ -f "/etc/hosts" ]; then
    echo "Files exists"
else
    echo "File not found"
fi

循环

bash
for i in {1..5}; do
    echo "Count $i"
done

定时任务 (Cron)

  • /etc/crontab: 系统级定时任务。
  • crontab -e: 编辑当前用户的定时任务。

格式: * * * * * command (分 时 日 月 周)

Released under the MIT License.