LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 10-03-2001, 06:09 AM   #1
mmvaldez
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, 08:45 AM   #2
DoubleLetter
Member
 
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:

./scriptname

NOT just scriptname

Good luck.
 
Old 10-03-2001, 04:35 PM   #3
mmvaldez
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
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.
 
Old 10-03-2001, 07:51 PM   #4
tomcf
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 09:19 PM.
 
Old 10-03-2001, 08:52 PM   #5
d3funct
Member
 
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
rwxr-xr-x
If not do "chmod +x {scriptname}" and try executing it.
 
Old 10-05-2001, 10:26 AM   #6
mmvaldez
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).
 
  


Reply


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 03:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 06:32 PM
Bin Shell Scripts jcai Linux - Newbie 3 09-15-2004 07:15 PM
Running a shell script via CGI-BIN chrisk5527 Linux - General 3 05-09-2003 12:44 PM
how to run a shell script which suffix is .bin??? yunxiang Linux - Software 2 05-05-2003 11:24 PM


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

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