0

我对 shell 脚本非常陌生,对我无法理解的所有内容都使用 man 命令。这是我的一段代码

$OUT="/try1.sh"
 if [ -a $OUT ]
 then
 rotate $OUT
 fi

ksh 中的 -a 做什么以及旋转命令是什么,因为在 ksh 中没有用于旋转的人工条目。

4

1 回答 1

1

-a[[ ]]or的条件表达式[ ]。它检查一个文件是否存在,-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
于 2013-09-11T15:10:51.630 回答