The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 07:34 PM
Not able to understand what's do the statement div_Neev Shell Programming and Scripting 1 02-20-2008 05:46 AM
Can't understand sar command shaan_dmp UNIX for Dummies Questions & Answers 1 10-23-2007 07:04 AM
can't understand BoyArcher UNIX for Dummies Questions & Answers 5 03-14-2006 09:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-19-2007
severndigital severndigital is offline
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
  #2 (permalink)  
Old 02-19-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
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
  #3 (permalink)  
Old 02-19-2007
severndigital severndigital is offline
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
  #4 (permalink)  
Old 02-19-2007
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,119
So you need to use:
#! /usr/local/bin/bash
as the first line of a bash script.
  #5 (permalink)  
Old 02-21-2007
Calum Calum is offline
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:46 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0