所以我有這個代碼
#!/bin/bash
> oldFiles.txt
files=$(grep " jane " ../data/list.txt | cut -d ' ' -f 3)
for i in $files ; do
if test -e ~$i; then echo "$i" >> oldFiles.txt;
fi
done
當我運行這些代碼時,oldFiles.txt 仍然是空的,但是在我在 if 陳述句中添加了一個正斜杠之后,就像在下面的代碼塊中一樣,代碼就可以作業了。
if test -e ~/$i; then echo "$i" >> oldFiles.txt;
那么添加和不添加正斜杠有什么區別?謝謝你。
uj5u.com熱心網友回復:
/是路徑分隔符。由于~擴展為/home/user沒有尾隨斜杠,~$i因此擴展為/home/userpathnot /home/user/path。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/439442.html
標籤:重击
