Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My script is as follows:


rm -rfv /home/user/Documents/Exercise/*

cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/Advanced/ /home/tp3/Documents/Exercise/

If i was to run these commands individually via Terminal they run ok. I have put them in a script (as above) and when I attempt to tun the script the Terminal windows flashes for about a second and nothing happens.

My attempts at solutions:

  1. Adding wait to the end of the script - no luck
  2. Right Click Script > Properties > Permissions > Execute - set
  3. Attempted to Run and Run in Terminal - no luck

I am using Ubuntu 12.10 64-bit

share|improve this question
Try to delete ` at the start/finish of script, on the other hand, first you delete a folder and in the next step you copy this folder to another location. Maybe first you want to copy the folder and after content its copied, delete it. – smile Mar 20 '13 at 8:22
the ` at the start of the script was just meant to add the code tag here on the forum sorry. I have a specific need to delete first. This code will be modified for different folders and files. So the delete command must come first. – Mitchell Mar 20 '13 at 11:16
When you say the Terminal window flashes, what do you mean? How are you running the script? If you're running it by making a Terminal window open just to run it and then close automatically, then what happens when you run your script manually in the terminal, by typing ./script, replacing script with the name of your script. (If that works, then it's especially important for you to explain precisely how you're running the script when it doesn't work.) – Eliah Kagan Mar 20 '13 at 11:21
The Terminal windows opens as if it is going to do something then closes almost instantly, hence it appears to flash. Here is the error when I run the script from terminal /home/user/Desktop/ bash: /home/user/Desktop/ /bin/sh^M: bad interpreter: No such file or directory – Mitchell Mar 20 '13 at 20:49
up vote 0 down vote accepted

After many more hours of tinkering I have found an unlikely answer.

I created a new blank document and added only the two lines I wanted (without the heading of #!/bin/sh) :

rm -rfv /home/user/Documents/Exercise/*
cp -rfv /home/user/Documents/ExerciseShare/ExerciseFiles/Word/Advanced/ /home/tp3/Documents/Exercise/

I then saved the document, right-click > properties > permissions > execute as program


Thanks to all that helped!

share|improve this answer

According to your comment, you had introduced an extra carriage return (\r) at the end of your shebang line

/bin/sh^M: bad interpreter

If you open your original file in vim, you'd see the ^M character; you could just remove it. Or you could open it in a hex editor such as hexedit, where you'd see an extra 0D.

Linux newlines are single newline characters (\n, 0x0A), as opposed to Windows newlines which still hark back to the days of typewriters (\r\n, 0x0D 0x0A).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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