0

I'm learning bash and have the following script

#!/bin/bash

mv myfile.txt myfileBACKUP.txt


echo "yo i love taylorswift
and i like blink182
ok done">> myfile.txt

mv myfileBACKUP.txt myfile.txt

the problem is that after I run script I still have myfileBACKUP.txt left and when I try to delete it I get error similar to this guy's The file cannot be moved to the trash. https://askubuntu.com/questions/164026/unable-to-delete-file-no-such-file-or-directory

Basically im looking to write a script which backs up an original file, create a new file and do something with the new file, then restore the original file.

Any help on how to do that and / or why I'm getting this garbage file leftover?

edit:

file permission from ls -la (the bad files doesn't show up in ls)

-rwxrwxr-x 1 odroid odroid 147 Dec 23 02:08 autodownloadv2.sh
-rw-rw-r-- 1 odroid odroid  45 Dec 23 02:59 myfile.txt

also the first time I run this myfile.txt doesn't exist so it throws an error I dont know if that has anything to do with this.

  • What are the permissions of the file and the directory? – glenn jackman Dec 23 '17 at 2:49
  • @glennjackman see edit – bakalolo Dec 23 '17 at 3:04
  • 2
    I tried your script and in both cases I'm able to move the files to the trash. What about the permissions of the directory? Are you doing this in your /home or in an external device? – nxnev Dec 23 '17 at 3:29
  • 2
    Why do you think you still have myfileBAKUP.txt left when the script runs, if you don't see it in ls? – Barmar Dec 23 '17 at 8:09
  • 1
    Seems like you need to refresh your file browser after the script has finished, and before you try to move a file into the trash that probably doesn't exist any more... – Murphy Dec 23 '17 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.