Results 1 to 4 of 4

Thread: Running commands from a script do not work

  1. #1
    Join Date
    Mar 2013
    Beans
    2

    Running commands from a script do not work

    Hi all!

    I am having some issues with a script, this is my first foray into Ubuntu and have read many guides, tutorials etc, so please be gentle!

    My script (copyword.sh) is as follows:


    Code:
    #!/bin/sh
    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 (opens as if it is about to do something and then closes) 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

    When I attempt to run the script via terminal as below I get an error:
    Code:
    /home/user/Desktop/copyword.sh
    Error:
    Code:
    bash: /home/user/Desktop/copyword.sh: /bin/sh^M: bad interpreter: No such file or directory
    Any help would be much appreciated!

    Cheers,
    Mitchell
    Last edited by mjohnston; March 21st, 2013 at 12:05 AM. Reason: Spelling.

  2. #2
    Join Date
    Apr 2007
    Location
    Kent, England
    Beans
    343
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Running commands from a script do not work

    try putting a full stop in front i.e.

    ./home/user/Desktop/copyword.sh

    or if in the folder

    ./copyword.sh

  3. #3
    Join Date
    Apr 2012
    Beans
    7,256

    Re: Running commands from a script do not work

    Quote Originally Posted by mjohnston View Post
    Code:
    bash: /home/user/Desktop/copyword.sh: /bin/sh^M: bad interpreter: No such file or directory
    It looks like you have Windows-style line terminations (CR-LF) in your file - you will need to run the file through dos2unix or use a text editor to remove them - see similar problem / solution here --> http://ubuntuforums.org/showthread.p...1#post12557331

  4. #4
    Join Date
    Mar 2013
    Beans
    2

    Re: Running commands from a script do not work

    Quote Originally Posted by steeldriver View Post
    It looks like you have Windows-style line terminations (CR-LF) in your file - you will need to run the file through dos2unix or use a text editor to remove them - see similar problem / solution here --> http://ubuntuforums.org/showthread.p...1#post12557331
    Perfect,

    This is the answer. Thank you very much!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •