Find the answer to your Linux question:
Results 1 to 8 of 8
Well basically i want to run bash script withoiut typing PHP Code: bash script . sh  As of now when I just type the filename im getting permissin denied... How can ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70

    Question how to run bash script as executable?


    Well basically i want to run bash script withoiut typing
    PHP Code:
    bash script.sh 
    As of now when I just type the filename im getting permissin denied...
    How can I make it work smoothly and like executable?


    Thanks!

  2. #2
    Linux Newbie mazer's Avatar
    Join Date
    Jul 2006
    Location
    Tucson, Arizona, USA
    Posts
    109
    you have to change the permissions.
    chmod u+x script.sh

    check with "man chmod" the whole syntax of "chmod".

    mazer

    PS: Do not forget to include #!/bin/bash at the top of your script.

  3. #3
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    Then once it's executable, put it in one of the directories in your $PATH. Type this command to see what those directories are:
    Code:
    echo $PATH
    That's what I've done for some of my games that use DosBox or Cedega, which makes it easier to add a link to the Desktop or K menu.
    Stand up and be counted as a Linux user!

  4. #4
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70
    I changed permissions (I think) but now Im getting "command not found"
    what and why?

  5. #5
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    well !! you must be in directory where script resides....
    or give full path of directory having script, to System PATH variable.

    $ export PATH=$PATH:/home/ur user name/directoy having scripts

    <=== { casper } ===>
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  6. #6
    Just Joined!
    Join Date
    Jul 2006
    Posts
    70
    casper i didnt really get what should i indicate as sysyemm path...

    $PATH variable returns me somwthing like this:

    /usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

  7. #7
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    hi alexus !!

    i saved all of my script files in folder /home/casper1/myscripts.
    now i use this command :

    $ export PATH=$PATH:/home/casper1/myscripts

    you have to give this command every time on login...

    to make it permanent... open file /home/<username>/.bashrc
    and write this command at end.

    from now on just typing file name will execute script files from anywhere... make sure to give executalbe permission to your scripts...

    $ chmod u+x script1

    <=== { casper } ===>
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  8. #8
    Linux User DThor's Avatar
    Join Date
    Jan 2006
    Location
    Ca..na...daaa....
    Posts
    319
    Alexus, be certain the first line of your script is the following:

    Code:
    #!/bin/bash
    exactly like that, no leading spaces, nothing else on the line. Making a script executable is part of the trick, but the shell needs to know what application you actually want to run - in this case, another bash. The #! is a special code that tells the shell this information, and it must be in the first column of the first line to work.

    DT

    [EDIT] just noticed Mazer already pointed this out, but you didn't acknowledge. Also, if this isn't it, just verify it runs ok by going to the location it's at, and running it. If you're running as root(I hope not!), be sure to do it like this:

    Code:
    ./myscript
    at least that tells you it's running OK. Then worry about paths.

Posting Permissions

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