Shell script does not recognize #!/bin/sh
I am a LInux newbie and am new to scripts as well. I am trying to use the #!/bin/sh in my scripts so that there wouldn't be any need to type in 'sh scriptname' every time and so would only need to type 'scriptname' as a command. I already changed the execute permissions. But still no go.
|
There are 2 possiblities:
1) The location of sh is incorrect. To find the correct location, type this command: which sh 2) To execute the script you have to type in: ./scriptname NOT just scriptname Good luck. |
Thanks for the reply, DoubleLetter.
I don't have a problem running a script by typing in: sh scriptname or . scriptname What I would like to achieve is to run my script as a command. That means running just the scriptname without preceding it with an sh or a '.'. I have read somewhere that this could be achieved by putting the line #!/bin/sh as the first line of the script but I haven't had much success. |
if the script is not in a directory stated in your PATH then you have 3 options:
1) put the script into your path, 2) add the directory in which the script resides to the path, or 3) use ./script to execute it (if its in `pwd`) You will also need to do what 'd3funct' says below ;) |
Does the script have the 'executable' bit set? When you do an "ls -la {scriptname}" does it show an "x" in any of the permissions? like
rwxr-xr-x If not do "chmod +x {scriptname}" and try executing it. |
Problem solved
Thanks for the responses.
What I didn't do was to add the subdirectory where my script resides. I didn't do it thinking that since I am running the script in its own subdirectory that it will work (shades of my MSDOS upbringing). |
All times are GMT -5. The time now is 12:58 PM. |