Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 10-03-2001, 05:09 AM   #1
LQ Newbie
Registered: Sep 2001
Posts: 10

Rep: Reputation: 0
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.
Old 10-03-2001, 07:45 AM   #2
Registered: Jun 2001
Location: Sharjah, United Arab Emirates
Distribution: Mandrake Linux 10.1
Posts: 132

Rep: Reputation: 15
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:


NOT just scriptname

Good luck.
Old 10-03-2001, 03:35 PM   #3
LQ Newbie
Registered: Sep 2001
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for the reply, DoubleLetter.

I don't have a problem running a script by typing in:

sh scriptname
. 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


as the first line of the script but I haven't had much success.
Old 10-03-2001, 06:51 PM   #4
LQ Newbie
Registered: Sep 2001
Location: Edmonton AB, Canada
Distribution: Debain/GNU Linux (Unstable)
Posts: 18

Rep: Reputation: 0
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

Last edited by tomcf; 10-03-2001 at 08:19 PM.
Old 10-03-2001, 07:52 PM   #5
Registered: Jun 2001
Location: Centralia, WA
Posts: 274

Rep: Reputation: 31
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
If not do "chmod +x {scriptname}" and try executing it.
Old 10-05-2001, 09:26 AM   #6
LQ Newbie
Registered: Sep 2001
Posts: 10

Original Poster
Rep: Reputation: 0
Thumbs up 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).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Bin Shell Scripts jcai Linux - Newbie 3 09-15-2004 06:15 PM
Running a shell script via CGI-BIN chrisk5527 Linux - General 3 05-09-2003 11:44 AM
how to run a shell script which suffix is .bin??? yunxiang Linux - Software 2 05-05-2003 10:24 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration