我正在尝试使用sed
删除包含变量$filegrep
的行:
filename=$(basename "$1")
filegrep=$(grep "$filename" /home/$USER/Desktop/Trash/Index/Index.txt)
filefir=$(dirname "filegrep")
我试图用这个命令来做:
sed -i '/$filegrep/d' /home/$USER/Desktop/Trash/Index/Index.txt
但是,我收到错误
sed: no input files
答案 0 :(得分:1)
'
中的字符串 - 引用的变量不会扩展变量:
marc@panic:~$ touch test.txt
marc@panic:~$ X=test.txt
marc@panic:~$ ls '$X' <---single-quoted
ls: cannot access $X: No such file or directory
marc@panic:~$ ls "$X" <---double-quoted
test.txt
将sed电话中的引号更改为"
:
sed -i "/$filegrep/d" /home/$USER/Desktop/Trash/Index/Index.txt
^-- ^--