Very simple script to copy a file


#copy file
mtp-getfile "6" test2.jpg

I set it as executable and run it using

sudo sh ./test.sh

It gives me a file called test2.jpg that has no icon and I cannot open I get a 'Failed to open input stream for file' error

However, if I simply issue the following from the command line

mtp-getfile "6" test2.jpg

It works as expected. What is wrong with my script? I checked and the resulting .jpg file in each case has the same number of bytes. Very strange.

  • can you use absolute path for test2.jpg – Kamaraj Dec 9 '16 at 17:49
  • if I understand you, it makes no difference. I'm in Desktop.(ubuntu) If I change to mtp-getfile "6" /home/ubuntu-mate/Desktop/foo_absolute.jpg still get a file I can't open if run from .sh script. But works from command line – Bachalo Dec 9 '16 at 18:06
  • did you execute your script with -x ? – Kamaraj Dec 9 '16 at 18:07
  • sudo ./test.sh -x same result – Bachalo Dec 9 '16 at 18:19
  • I wonder if its a permissions issue? When I check permissions of the file I can't open I only see root. Also there is a locked icon – Bachalo Dec 9 '16 at 18:20

Need to do

sudo chown <user> <copied file name>

Not sure why permissions would be different in each case

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.