Find the answer to your Linux question:
Results 1 to 8 of 8
Hi, I'm new to linux and have a basic question. I have created a shell script and made it executable with Code: chmod 755 my-script.sh Looking at the permissions of ...
  1. #1
    jut
    jut is offline
    Just Joined!
    Join Date
    Apr 2007
    Posts
    10

    Can't execute shell scripts (easy question)

    Hi,

    I'm new to linux and have a basic question.

    I have created a shell script and made it executable with

    Code:
    chmod 755 my-script.sh
    Looking at the permissions of the file, it now reads...

    Code:
    -rwxr-xr-x  1 jut jut   14 2007-04-01 00:22 my-script
    So I try to execute it using...
    Code:
    $ my-script
    -bash: my-script: command not found
    wtf...

  2. #2
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Hi jut,

    Welcome to the LinuxForums.

    execute script like this
    Code:
    sh my-script.sh
    you have set executing bit already (chmod). ./my-script.sh will also work.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  3. #3
    Linux User
    Join Date
    Feb 2006
    Posts
    484
    or like this
    ./my-script.sh

    if you run your srcipts in "sh anyscript.sh" format you needn't change the permissions

  4. #4
    jut
    jut is offline
    Just Joined!
    Join Date
    Apr 2007
    Posts
    10
    Quote Originally Posted by devils_casper
    you have set executing bit already (chmod). ./my-script.sh will also work.
    I have most definitely set the executable permissions, yet it still won't execeute....

    Code:
    jut@JPS:~$ ls -laFh
    -rwxr-xr-x   1 jut  jut     14 2007-04-01 00:22 my-script*
    Look there's even an asterisks next to it! What's the deal....

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    what error does it throw?
    Code:
    ./my-script
    sh my-script
    post exact error message here.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    jut
    jut is offline
    Just Joined!
    Join Date
    Apr 2007
    Posts
    10
    Code:
    jut@JPS:~$ more my-script
    #!/bin/sh
    ls
    jut@JPS:~$ my-sript
    -bash: my-sript: command not found
    jut@JPS:~$ sh my-script
    asdf          backmeup       backup_script_old  foundmp3s  jill          juts_files.tar.gz  MP750.zip     my-script  pix       setup_files       stuff-that-runs-when-i-start-this-linux-box  zspw
    automate_scp  backup_script  Desktop            jack       jut_bkup.iso  mp3                mypix.tar.gz  PIC        programs  some-deep-folder  todo-list
    jut@JPS:~$

  7. #7
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    sh my-script is working. if you prefix ./ before my-script, that will also work.
    if you want to execute script without prefixing ./ or sh, you have to add path of folder having 'my-script' file in PATH variable.
    Code:
    PATH=$PATH:<path_of_folder>
    my-script
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  8. #8
    jut
    jut is offline
    Just Joined!
    Join Date
    Apr 2007
    Posts
    10
    Oh that's interesting. Thanks!

Posting Permissions

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