我試圖在bash腳本中執行diff
命令時出現一個非常令人驚訝的問題。當提供一個包含代字號的路徑變量時,bash diff無法找到現有文件(〜)
這裏是工作的代碼說明了這一點:
#!/bin/bash
cd
mkdir foo bar
head -c 1024 /dev/urandom >foo/qux
head -c 1024 /dev/urandom >bar/qux
# works properly as expected
diff ~/{foo,bar}/qux
folder="~"
# this fails with the ~ inside a variable
diff $folder/{foo,bar}/qux
# cleaning the mess
rm -rf foo bar
所以我的問題是:
hahahaha :)非常感謝你 –