Find the answer to your Linux question:
Results 1 to 7 of 7
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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.


  2. #2

    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/
    File "/home/mskiles/Desktop/", line 3
    echo "Legends installer - starting installation... please wait"
    SyntaxError: invalid syntax"

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

  3. #3
    SuperMod (Back again) devils casper's Avatar
    Join Date
    Jun 2006
    Chandigarh, India
    post your script here.

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

  4. $spacer_open
  5. #4
    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:
    chmod +x
    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.

  6. #5


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

  7. #6
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    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:
    # @(#) 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:
    # @(#) s1       Demonstrate altercate methods of executing script.
    ls -l s2
    echo "1) Feed it into the shell."
    sh s2
    echo "2) - almost the same, re-direct stdin."
    sh <s2
    echo "3) Use the "." command."
    . s2
    The results from s1:
    % ./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 )

  8. #7
    Linux Newbie X.Cyclop's Avatar
    Join Date
    May 2006
    chmod +x #Allow execution
    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