我是shell脚本的新手,并且使用man命令来处理我无法理解的一切。 这是我的一段代码
$OUT="/try1.sh"
if [ -a $OUT ]
then
rotate $OUT
fi
在ksh中什么是-a做什么和什么是rotate命令,因为在ksh中没有用于旋转的man条目。
答案 0 :(得分:1)
-a
是[[ ]]
或[ ]
的条件表达式。它检查文件是否与-e
相同但是是过时的版本。
如上所述:
A conditional expression is used with the [[ compound command to test attributes of files and to compare strings. Field splitting and file name generation are not
performed on the words between [[ and ]]. Each expression can be constructed from one or more of the following unary or binary expressions:
string True, if string is not null.
-a file
Same as -e below. This is obsolete.
-e file
True, if file exists.
对于您的脚本,它会检查/try1.sh
是否存在。我还建议使用这种格式:
OUT="/try1.sh" ## When assigning a value to a variable, don't include the dollar sign ($).
if [[ -a $OUT ]]; then ## Use [[ ]]
rotate "$OUT" ## Quote your variables inside ""
fi