Find the answer to your Linux question:
Results 1 to 7 of 7
I know I've done this before... I thought it was as simple as running the file in the terminal, however that isn't working. Does anyone know if there is a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    How to run .sh files?


    I know I've done this before... I thought it was as simple as running the file in the terminal, however that isn't working.

    Does anyone know if there is a command I need to type before running an .sh file?

    I thought it might have been py but that didn't work.

    Thanks.

  2. #2
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    A little farther now...

    Ok it turns out the command is python. Makes sense, but I could've sworn it was py.

    So when I run the code it says:

    "desktop:~$ python /home/mskiles/Desktop/legends_linux_0.4.1.40.sh
    File "/home/mskiles/Desktop/legends_linux_0.4.1.40.sh", line 3
    echo "Legends installer 0.4.1.40 - starting installation... please wait"
    ^
    SyntaxError: invalid syntax"

    So I'm a little farther now, does anyone know what's going wrong?

  3. #3
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,729
    post your script here.






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

  4. #4
    Just Joined!
    Join Date
    Jul 2006
    Posts
    27
    Generally, .sh-scripts are Bourne Shell scripts or Bourne Again Shell scripts.

    So long as a script has a proper shebang-line, you should be able to run them as follows:
    Code:
    chmod +x ShellScript.sh
    ./ShellScript.sh
    The chmod only needs to be run once if the execute-flag isn't set. After the proper execute permissions have been set, they can be executed just like any normal executable. The shebang line* takes care of the executable that will interpret the file.

    *The shebang line is the first line of the script, starting with a pound sign [ # ] and an exclamation mark [ ! ]. The shebang line is usually #!/bin/sh or #!/bin/bash, though it can also be (but is not limited to), for example, #!/usr/bin/perl or #!/usr/bin/python.

  5. #5
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    Thanks

    that was it. I forgot to run chmod, I hadn't made it executable. Thanks a lot though

  6. #6
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,260
    Hi, SpaceballOne.

    Most of the time we do want execute permission on scripts because that makes life convenient for us.

    However, you don't need execute permission, and there are a number of alternate ways to execute a script.

    Consider the trivial script:
    Code:
    #!/bin/sh
    
    # @(#) s2       Print hello world.
    
    SCRIPT=$(basename $0)
    echo "Hello, world from $SCRIPT."
    The next script is going to execute s2, but s2 does not have execute permission as you will see:
    Code:
    #!/bin/sh
    
    # @(#) s1       Demonstrate altercate methods of executing script.
    
    ls -l s2
    
    echo
    echo "1) Feed it into the shell."
    sh s2
    
    echo
    echo "2) - almost the same, re-direct stdin."
    sh <s2
    
    echo
    echo "3) Use the "." command."
    . s2
    The results from s1:
    Code:
    % ./s1
    -rw-r--r--  1 drl drl 97 Jul 31 16:17 s2
    
    1) Feed it into the shell.
    Hello, world from s2.
    
    2) - almost the same, re-direct stdin.
    Hello, world from sh.
    
    3) Use the . command.
    Hello, world from s1.
    There's always more than one way of doing things in *nix ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  7. #7
    Linux Newbie X.Cyclop's Avatar
    Join Date
    May 2006
    Location
    Israel
    Posts
    143
    Code:
    chmod +x File.sh #Allow execution
    sh ./File.sh #Run it
    "Don't think about the work, think about the benefit"

    Leonardo Juszkiewicz

Posting Permissions

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