The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Code Understand ? varungupta UNIX for Advanced & Expert Users 2 05-02-2008 04:34 PM
Not able to understand what's do the statement div_Neev Shell Programming and Scripting 1 02-20-2008 02:46 AM
Can't understand sar command shaan_dmp UNIX for Dummies Questions & Answers 1 10-23-2007 04:04 AM
can't understand BoyArcher UNIX for Dummies Questions & Answers 5 03-14-2006 06:36 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 02-19-2007
Registered User
 

Join Date: Feb 2007
Posts: 2
can't understand this at all.

Ok, i've been trying to write some shell scripts. nothing challenging, but just automating

All of the tutorials i read say to start the file with

#!/bin/bash

or whatever your path to bash is.

So i do it, and all of my scripts error out saying ./nameofscript:command not found

when i remove the line completely the script seems to run ok. Why??

I understand the easy answer is to say "so just leave the line out" but I really would like to understand why it's happening.

thanks,
chris
Reply With Quote
Forum Sponsor
  #2  
Old 02-19-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,618
First, read this: What does "#! /usr/bin/ksh" mean?

And then you need to figure out where bash is, if you have it at all. What OS are you using? Run the command "uname -a" and post the results so we know. "echo $SHELL" will probably tell you what shell you are using. Also try:
which bash
which ksh
Reply With Quote
  #3  
Old 02-19-2007
Registered User
 

Join Date: Feb 2007
Posts: 2
thanks for that link. apparently I am about 50 steps ahead of myself


uname -a result
Code:
FreeBSD PCBSD.localhost 6.1-RELEASE-p2 FreeBSD 6.1-RELEASE-p2 #1: Thu Jul  6 11:31:02 PDT 2006     root@PCBSD.localhost:/usr/obj/usr/src/sys/PCBSDv1.2  i386
$SHELL result
Code:
/bin/csh
which bash & which ksh
Code:
PCBSD# which bash
/usr/local/bin/bash
PCBSD# which ksh
ksh: Command not found.
thanks for any input / help .. I am eager to code some scripts ..

chris
Reply With Quote
  #4  
Old 02-19-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,618
So you need to use:
#! /usr/local/bin/bash
as the first line of a bash script.
Reply With Quote
  #5  
Old 02-21-2007
Registered User
 

Join Date: Jun 2002
Location: Edinburgh
Posts: 39
by the way, i suspect the reason your script runs fine without that line has something to do with it running using *your* shell. As above, it's much more sensible to specify the path to a command interpreter explicitly, since then you can specify which command interpreter to use in each script (for example, if you have different scripts that use different command interpreters). Depending on how your system's set up, you'd usually have to type "sh ./nameofscript" or something similar to run a script using an interpreter other than the one specified.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:05 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0