在Linux中,您可以執行簡單的命令行條件,例如。是否可以合併兩個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
是否有可能兩個條件結合成一個?所以如果找到了狐狸,我們會查看該文件是否存在,然後相應地執行該條件。
我曾嘗試以下,他們似乎並沒有工作:
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'
我需要的命令,發生在同一行。
這只是顯示錯誤:{:命令未找到。 未找到文件 }:未找到命令。 找不到 – difurious
你用的是什麼外殼?這對'bash'我很好# – anubhava
我正在使用-csh – difurious