2

I'm trying to make a sort of recycling bin. I have a delete function which sends the selected file to the recycling bin and adds the location of the directory it was stored in to the file. The problem is when I obtain the location from the script using tail. Although the script works, it renames the file to tail. Could anyone explain why the cp is renaming the file? Here is a snippet from where I believe the problem is:

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

Thanks

melpomene
  • 84,125
  • 8
  • 85
  • 148

3 Answers3

2

You need a $ before the parenthesis:

destination=$(tail $1 -n 1)
cp ~/Recycling/$1 $destination 
rm ~/Recycling/$1
sed -i '$d' $destination # this removes the last line from the file
perreal
  • 94,503
  • 21
  • 155
  • 181
1

You're missing a $ before the parens:

destination=$(tail $1 -n 1)
melpomene
  • 84,125
  • 8
  • 85
  • 148
0

You would want

$(tail $1 -n 1)

or

`tail $1 -n 1`
Eugen Rieck
  • 64,175
  • 10
  • 70
  • 92