我对这些运算符在 bash 中使用时有何不同(括号、双括号、括号和双括号)感到有些困惑。
[[ , [ , ( , ((
Run Code Online (Sandbox Code Playgroud)
我见过人们在这样的 if 语句中使用它们:
if [[condition]]
if [condition]
if ((condition))
if (condition)
Run Code Online (Sandbox Code Playgroud) 或者,有关强大的文件名处理和在 shell 脚本中传递的其他字符串的介绍性指南。
我写了一个 shell 脚本,它在大多数情况下运行良好。但它在某些输入(例如某些文件名)上窒息。
我遇到了如下问题:
hello world,它被视为两个单独的文件hello和world.\[*?,它们会被一些文本替换,这实际上是文件的名称。'(或双引号"),在那之后事情变得很奇怪。\分隔符)。这是怎么回事,我该如何解决?
当脚本在一年的开始两天运行时,我使用下面的脚本将两天后移,并检查每个月的第一天和第二天,然后将后移两天。
if [$month="01"] && [$day="01"]; then
date="$last_month/$yes_day/$last_year"
fulldate="$last_month/$yes_day/$last_year"
else
if [$month="01"] && [$day="02"]; then
date="$last_month/$yes_day/$last_year"
fulldate="$last_month/$yes_day/$last_year"
else
if [ $day = "01" ]; then
date="$last_month/$yes_day/$year"
fulldate="$year$last_month$yes_day"
else
if [ $day = "02" ]; then
date="$last_month/$yes_day/$year"
fulldate="$year$last_month$yes_day"
else
date="$month/$yes_day/$year"
fulldate="$year$month$yes_day"
fi
fi
fi
fi
Run Code Online (Sandbox Code Playgroud)
但我的坏消息是收到以下错误消息
Etime_script.sh: line 19: [06=01]: command not found
Etime_script.sh: line 24: [06=01]: command not found
Run Code Online (Sandbox Code Playgroud)