shell脚本问题

Catalogue
  1. 1. if
  2. 2. shell 中的条件判断 “并且” “或者”
  3. 3. 加减
  4. 4. 定时任务中脚本不能执行

if

if始终只是判断程序执行结果的exit status,即$?,0表示true,非0表示false。

1
[ -d /root/test ]等同于test -d /root/test

shell 中的条件判断 “并且” “或者”

并且,and

1
2
3
4
5
6
7
if [ c1 -a c2 ]; then

fi

if [ c1 ] && [ c2 ]; then

fi

或者,or

1
2
3
4
5
6
7
if [ c1 -o c2 ]; then

fi

if [ c1 -o c2 ]; then

fi

加减

1
2
3
let a=$s+1

$(($s+1))

定时任务中脚本不能执行

1
2
3
4
5
6
手动执行脚本可以运行,但在crontab里面不行的解决方法

source /etc/profile
. ~/.bash_profile
#!/bin/bash
##执行shell脚本的命令