bash - “( doSomething ) || :” 的意思
bash - meaning of "( doSomething ) || :"
我偶然发现了这行代码:
( cd ${TRASH_DIR} && rmdir 20* 2> /dev/null ) || :
第一个表达式对我来说很清楚,但是 "else-Part" 的含义是什么:只是“:
”?大多数情况下,我在这些情况下看到“|| exit 1
”,这对我来说也很清楚。
PS:不幸的是,我似乎无法 google 这个字符组合而没有提示它的含义...
“:”shell字符含义的定义可在here中找到。这是您需要定位的片段;在这个冗长的页面上很难被搜索到:
:
null command [colon]. This is the shell equivalent of a "NOP" (no op, a do-nothing operation). It may be considered a synonym for the shell builtin true. The ":" command is itself a Bash builtin, and its exit status is true (0).
在您问题中考虑的代码行中,它仅用于确保表达式的最终退出代码为 0,与那里检查的条件无关。
我偶然发现了这行代码:
( cd ${TRASH_DIR} && rmdir 20* 2> /dev/null ) || :
第一个表达式对我来说很清楚,但是 "else-Part" 的含义是什么:只是“:
”?大多数情况下,我在这些情况下看到“|| exit 1
”,这对我来说也很清楚。
PS:不幸的是,我似乎无法 google 这个字符组合而没有提示它的含义...
“:”shell字符含义的定义可在here中找到。这是您需要定位的片段;在这个冗长的页面上很难被搜索到:
:
null command [colon]. This is the shell equivalent of a "NOP" (no op, a do-nothing operation). It may be considered a synonym for the shell builtin true. The ":" command is itself a Bash builtin, and its exit status is true (0).
在您问题中考虑的代码行中,它仅用于确保表达式的最终退出代码为 0,与那里检查的条件无关。