Doubt in shebang line!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Doubt in shebang line!!
# 1  
Old 11-25-2008
Lightbulb Doubt in shebang line!!

Do we need to include the exclamatory mark in the shebang line??Smilie
What if we dont include it??Smilie

Actually what shebang line implies when we run a script??

shebang line--> #!/bin/ksh Smilie
# 2  
Old 11-25-2008
# 3  
Old 11-25-2008
Even if i dont include it, ma sscript is running fine..

so whats the point in including it??Smilie
# 4  
Old 11-25-2008
Consider this, for example:

Code:
$ ps -p $$
      PID    PPID    PGID     WINPID  TTY  UID    STIME COMMAND
     2616    3828    2616       4044    1 1003 11:56:15 /usr/bin/bash
$ cat s  
#! /usr/local/bin/zsh

print -l **/*(/)
$ ./s
backup
dir1
$ sed -i 1d s
$ cat s

print -l **/*(/)
$ ./s
./s: line 2: syntax error near unexpected token `('
./s: line 2: `print -l **/*(/)

# 5  
Old 11-25-2008
hi radoulov,

am working in ksh and i tried ur snippet..its not givin any error if we don include shebangSmilie
# 6  
Old 11-25-2008
So you get the idea, try executing it from another shell ...

Code:
$ ksh -c 'print -l **/*(/)'  
ksh: print: -l: unknown option
$ ksh93 -c 'print -l **/*(/)'
/var/opt/ast/bin/ksh[1]: print: -l: unknown option
Usage: print [-enprsv] [-f format] [-u fd] [string ...]
$ zsh -c 'print -l **/*(/)' 
backup
dir1
$ bash -c 'print -l **/*(/)' 
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `print -l **/*(/)'
$ dash -c 'print -l **/*(/)'
zsh: correct 'dash' to 'ash' [nyae]? y
Syntax error: "(" unexpected
$ sh -c 'print -l **/*(/)' 
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `print -l **/*(/)'
$ csh -c 'print -l **/*(/)'
Badly placed ()'s.
$ tcsh -c 'print -l **/*(/)'
Badly placed ()'s.
$ pdksh -c 'print -l **/*(/)'
pdksh: print: -l: unknown option

# 7  
Old 11-25-2008
It just helps you in using the intended shell, for example time in csh isn't the same in ksh, it's built in and different. The ksh uses /usr/bin/time (depends I'm sure).
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about Shebang line of Bash Script

Hello All, I was writing a Bash shell script that will be executed on both an AIX server (/usr/bin/ksh) and a SLES server (/bin/bash). The AIX server has Bash installed at "/usr/bin/bash", which is in a different dir then the SLES server. So basically I am writing the script on the SLES... (4 Replies)
Discussion started by: mrm5102
4 Replies

2. Shell Programming and Scripting

Scripts without shebang

I see lot of ad-hoc shell scripts in our servers which don't have a shebang at the beginning . Does this mean that it will run on any shell ? Is it a good practice to create scripts (even ad-hoc ones) without shebang ? (16 Replies)
Discussion started by: kraljic
16 Replies

3. Shell Programming and Scripting

Necessity of shebang line

Hi , I know about the shebang line in shell scripting. Just want to know whether is there any difference in execution of the program by keeping and not keeping the shebang line. Because without shebang line also the script is working. correct me if am wrong. Any help on this will be helpful (5 Replies)
Discussion started by: rogerben
5 Replies

4. Shell Programming and Scripting

csh shebang query

What does the "-f" mean in following interpreter code #!/bin/csh -f Thank you (2 Replies)
Discussion started by: animesharma
2 Replies

5. Shell Programming and Scripting

Shebang

If i am not using #! in my script. By default where will be my script running? (6 Replies)
Discussion started by: Kochu77
6 Replies

6. Shell Programming and Scripting

The Shebang!

Hi, I always thought that #!/usr/bin/ksh means that the script would be executed in korn shell i.e. when we'll execute the script with this line as the very first line then the shell spawns a korn shell (in this case as we are using #!/usr/bin/ksh ) and the script gets executed. But I am... (7 Replies)
Discussion started by: dips_ag
7 Replies

7. Shell Programming and Scripting

Multiple shebang lines

*** EDIT: I found something close to my solution under an IIS 7 Module Handle.***** (Non-Homework question, simply an ease of use one) Odd question here and maybe its my newness to cgi/Perl, but is it possible to have 2 shebang lines? I write an test a ton of my homework code on my windows... (1 Reply)
Discussion started by: sennex
1 Replies

8. Shell Programming and Scripting

Relacing the shebang line of a file

Can any one tell me how to replace a shebang line of a file using sed? Eg: If a file contains the following shebang line #!C:/InstantRails/ruby/bin/ruby I would like to replace it with #!/usr/local/bin/ruby The shebang line of the file can be obtained from the command cat... (3 Replies)
Discussion started by: linuxnewbe
3 Replies

9. Shell Programming and Scripting

Shebang

Hi, I am currently writing BASH shell scripts. I am using BASH on a Powerbook G4 running Leopard. Could somebody please explain the difference between #!/bin/bash and #!/bin/sh? I have been using the latter (#!/bin/sh), and things have been working fine. But is that the correct one to use... (9 Replies)
Discussion started by: msb65
9 Replies
Login or Register to Ask a Question