2

我正在尝试制作一种回收箱。我有一个删除功能,它将所选文件发送到回收站,并将其存储的目录的位置添加到文件中。问题是当我使用 tail 从脚本中获取位置时。尽管该脚本有效,但它将文件重命名为tail。谁能解释为什么cp要重命名文件?这是我认为问题所在的片段:

destination=(tail $1 -n 1)
cp ~/Recycling/$1 $destination 
rm ~/Recycling/$1

谢谢

4

3 回答 3

2

你需要一个$括号前:

destination=$(tail $1 -n 1)
cp ~/Recycling/$1 $destination 
rm ~/Recycling/$1
sed -i '$d' $destination # this removes the last line from the file
于 2012-11-27T01:20:59.127 回答
1

您在$括号之前缺少 a :

destination=$(tail $1 -n 1)
于 2012-11-27T01:21:03.537 回答
0

你会想要

$(tail $1 -n 1)

或者

`tail $1 -n 1`
于 2012-11-27T01:21:18.477 回答