can't understand this at all.


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers can't understand this at all.
# 1  
Old 02-19-2007
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  
Old 02-19-2007
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  
Old 02-19-2007
thanks for that link. apparently I am about 50 steps ahead of myself Smilie


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  
Old 02-19-2007
So you need to use:
#! /usr/local/bin/bash
as the first line of a bash script.
# 5  
Old 02-21-2007
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.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

understand sed

cat teledir.txt jai sharma 25853670 chanchal singhvi 9831545629 anil aggarwal 9830263298 shyam saksena 23217847 lalit chowdury 26688726 If i use the below command , it is giving me the output with "," in between two name. how ? and also i would like to know the reason for the space used in... (1 Reply)
Discussion started by: Antony Ankrose
1 Replies

2. Shell Programming and Scripting

Not able to understand IFS

Hi , i am in my initial learning phase of unix. i was going thru the function part. below is the example which was there but i am not able to understand logic and the use of IFS(internal field separator) lspath() { OLDIFS="$IFS" IFS=: for DIR in $PATH ; do echo $DIR ; done IFS="$OLDIFS"... (8 Replies)
Discussion started by: scriptor
8 Replies

3. Shell Programming and Scripting

can't understand!

Hi All, can you please help me to figured out what's the meaning of this. ${SERVER_DATABASE} -b << EOF 2>>/dev/null THanks, (3 Replies)
Discussion started by: nikki1200
3 Replies

4. Shell Programming and Scripting

help can't understand the code

Hi All, Good day, i'm just wondering what is the meaning of this code? COUNT_EXTRACTED_FILE=`${ECHO_CMD} "${SE_IN_PATH}${SE_IN_FILE}" | ${AWK_CMD} -F"__" '{print $2}'` Thanks, -niks(newbie) (2 Replies)
Discussion started by: nikki1200
2 Replies

5. Programming

Trying to understand kernel

Hi all, I'm a user and a programmer of UNIX based systems (mainly FreeBSD and Linux). I have never programmed or tried to fully understand the kernel layer. I haven't a special propouse for learning it, but I'd like to. Can anyone suggest me books, documentation or examples that may help me... (2 Replies)
Discussion started by: mghis
2 Replies

6. Solaris

Understand PATH

I'm new to unix so sorry for the confusing question. I installed OPENSSL following these instructions. Installing OpenSSH Packages - SPARC and Intel/Solaris 8 I need to run this command, "openssl req -newkey rsa:1024 -keyout server.pf.key -out req.pem" from a keyreq folder I created. ... (13 Replies)
Discussion started by: Kjons76
13 Replies

7. Shell Programming and Scripting

Can't quite understand this regex

The following regular expression is found in a book I have been reading. It apparently can be used on an /etc/passwd file to find any accounts which have no password. I am having a heck of a time seeing how it works, and I was wondering if someone could run me through it. I will take a stab at... (1 Reply)
Discussion started by: kermit
1 Replies

8. UNIX for Dummies Questions & Answers

can't understand

how i can download this game n start it :S (5 Replies)
Discussion started by: BoyArcher
5 Replies
Login or Register to Ask a Question