文件存在输出yes,否则输出no。
shell终端执行:
[ -f hello.txt ] && echo yes || echo no
-f 文件名字
文件存在则为真。- 执行
[ -f hello.txt ]
为真则执行echo yes
,由于或语句||
的存在echo no
不再执行。 - 特别地,这里的逻辑与和逻辑或值得仔细思考。
文件存在输出yes,否则输出no。
shell终端执行:
[ -f hello.txt ] && echo yes || echo no
-f 文件名字
文件存在则为真。[ -f hello.txt ]
为真则执行echo yes
,由于或语句||
的存在echo no
不再执行。