使用mv或rm我會使用該-f標志,但我確定如何為cat.
有沒有辦法做到這一點?可以處理這種極端情況的替代方案?還是單行try/except可以處理這種邊緣情況?
例如,
cat path/to/potential_files/*.fa > output.fa
cat: 'path/to/potential_files/*.fa': No such file or directory
uj5u.com熱心網友回復:
你可以寫try ... catch ...一個
cat file 2>/dev/null ||
{
echo 'Catch block, only reached when $? -ne 0'
echo 'Another catch statement'
}
# Or oneliner (note the spaces around the curly braces and the semicolons)
cat file 2>/dev/null || { echo 'Something '; echo 'else'; }
uj5u.com熱心網友回復:
您可以使用 globbing 遍歷與 .fa 匹配的所有檔案,并使用>>附加到outout檔案:
for file in "$YOUR_PATH/*.fa"; do
cat "$file" >> outout_file.txt
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/449208.html
