linux – bash如果在crontab作业中出现statment意外行为
发布时间:2020-12-14 02:50:42 所属栏目:Linux 来源:网络整理
导读:这是脚本 bash --version | head -n1if [ "$1" == "now" ]then echo if now execut jobelse echo else "_"$1"_" # make sure we are not picking any spaces if [ condition ] then execut something else fifi./script nowif now 如果从交互式shell运行,则
这是脚本
bash --version | head -n1 if [ "$1" == "now" ] then echo if now execut job else echo else "_"$1"_" # make sure we are not picking any spaces if [ condition ] then execut something else fi fi ./script now if now 如果从交互式shell运行,则按预期工作.但是,如果从cron as调用,则if转到else块 * * * * * root /home/user/./script now >> /tmp/log cat /tmp/log GNU bash,version 4.3.11(1)-release (x86_64-pc-linux-gnu) else _now_ 与“-eq”相同. 我错过了一些简单的东西,因为我还没吃早餐吗? 运行Ubunt 14.04LTS. 解决方法
因为语法只有一个相等:[$a = $b]
if [ ! $a = $b ]; then #with space in condition and need instruction between then and fi,else doesn't works ...Script to execute... elif [ ! $a = $c ]; then ...Script to execute... else ...Script to execute... fi 条件sh列表 [ $a = $b ] && return 1 || return 0 conditionnal alternative format if [ $a = $b -o $b = $c ] -o mean OR if [ $a = $b -a $b = $c ] -a mean AND if [ $a = $b -o $b = $c ] || [ $a = $b -a $a = $c ] multiple conditionnal or if [ $a = $b -o $b = $c ] && [ $a = $b -a $a = $c ] multiple conditionnal and if [ -z $a ] is empty or null if [ ! -z $a ] not equal to "" if [ -n $a ] is not empty or null if [ $a -eq $b ] equal (numeric) if [ $a -ne $b ] not equal (numeric) if [ $a -gt $b ] greater than (numeric) if [ $a -ge $b ] greater or equal than (numeric) if [ $a -lt $b ] lower than (numeric) if [ $a -le $b ] lower or equal than (numeric) if [ -d $a ] is a directory if [ -e $a ] file exist if [ -f $a ] is a file if [ -g $a ] is group allowed for the file if [ -r $a ] is readable if [ -s $a ] file is not 0kb if [ -u $a ] is user allowed for file if [ -w $a ] is writable if [ -x $a ] is executable 更多与bash if [[ "$a" =~ "$b" ]] match (reg exp) if [[ $a == *$b* ]] match (glob) if [ "${a/$b}" = $a ] match (string) if [ -z "${a##*$b*}" ] match (string,work with dropbox !) if [ ${a/$b} = $a ] match (string) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
- linux – Shell识别文件?但不在?/ Documents中
- 备份 – 如何使用一个wget / curl下载所有我的ca
- linux – 在unix one-liner中将* .foo更改为* .b
- terminal – tmux key bind C-Tab(Ctrl Tab)切换
- linux – 如何验证VMWare ESX主机上的CentOS Gue
- linux – nginx对动态内容有用吗?
- linux – 如何告诉start-stop-daemon将$HOME和$U
- Linux / C:获取用户目录而不泄漏
- linux – 如何使.bashrc中的更改在当前终端中有
- 使用sed替换shell脚本中的特殊字符
热点阅读