【发布时间】:2017-02-16 15:00:14
【问题描述】:
在 Linux 中,您可以执行简单的命令行条件,例如。
echo 'The short brown fox' | grep -q 'fox' && echo 'Found' || echo 'Not Found'
>> Found
或者
test -e test.txt && echo 'File Exists' || echo 'File Not Found'
>> File exists
这两个条件可以合二为一吗?因此,如果找到 fox,我们会查看文件是否存在,然后相应地执行条件。
我尝试了以下方法,但它们似乎不起作用:
echo 'The short brown fox' | grep -q 'fox' && (test -e test.txt && echo 'File Exists' || echo 'File Not Found') || echo 'Fox Not Found'
echo 'The short brown fox' | grep -q 'fox' && `test -e test.txt && echo 'File Exists' || echo 'File Not Found'` || echo 'Fox Not Found'
我需要在一行中执行命令。
【问题讨论】:
标签: csh