[英]Fish shell - remove file and execute command
我想執行簡單的命令
rm -f *.zip or true ; and date
意味着我想刪除當前路徑中的所有zip文件並顯示當前日期。 我還是想看看日期。 即使沒有這樣的文件。
我會在bash中這樣做:
rm -f *.zip || true; date
這就是我的魚:
更新
閱讀文檔我發現
結果證明(我不敢相信)
我應該將簡單的rm -f *.zip
編寫為
set files *.zip
if count $files > /dev/null
rm -f *.zip
end
我對這種解決方案感到非常不滿,
一定有更好的東西
我嘗試過的更新
rm -f "*.zip"; date
但是它不會刪除文件,因為不會發生擴展
更新資料
我雖然在函數中隱藏表達式
function rmf
set files $argv
set quantity (count $files)
if [ $quantity -gt 0 ]
echo "yes";
rm -f $files
else
echo "not enough"
end
end
但是問題是rmf函數沒有被視為count函數
我同意,這是一個令人沮喪的案例。 fish的通配符擴展行為幾乎總是更好(嘗試使用bash中的touch *.zip
來查看原因),這是非常重要且令人討厭的rm
例外。
可能最簡單的解決方法是:
set tmp *.zip ; rm -f $tmp ; date
set files *.zip
set -q files[1]
and rm -f $files
date
最終命令:
rm -f *.zip ; date
當我遇到使用魚2.2的問題時,它在魚2.6中可以正常工作。 他們在以后的版本中更改了行為。
加上一些警告:
無需和日期之前,它的行為就像&&在bash因此它會忽略
是的,它會產生錯誤,但它應該執行的操作
看到這個問題https://github.com/fish-shell/fish-shell/issues/683
確切說明原因:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.