Usage of #!/bin/ksh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Usage of #!/bin/ksh
# 1  
Old 08-30-2011
Usage of #!/bin/ksh

Hi,

In the beginning of Shell script, we give a statement like
#!/bin/ksh

I have 2 questions related to this,

1) It could denote about the shell we want to use, what is the real usage of this? My shell script works even without this statement, is it a mandatory one.

2) I'm using bash shell, for this, can I give it as #!/bin/sh

Please advise.

Thank you.
# 2  
Old 08-30-2011
This User Gave Thanks to yazu For This Post:
# 3  
Old 08-30-2011
Hi,

Thank you for the link.

Can you put it in your own terms with examples.
# 4  
Old 08-30-2011
Why? Is this an interview question? Or home-/coursework? If you've got problems with understanding the article, please state them, instead of asking generalized questions.
# 5  
Old 08-30-2011
Quote:
Originally Posted by Dev_Dev
Hi,

Thank you for the link.

Can you put it in your own terms with examples.
???

Link seems pretty clear to me, including the examples. How would you like it worded or expanded?
# 6  
Old 08-30-2011
In a nutshell, the first 2 characters happen to be the ascii representation of the hex values 0x23 0x21 which is a "magic number" that the shell interpreter uses. When the interpreter sees the #! as the first 2 characters, it builds a command line consisting of the remaining characters after the #! followed by the filename itself along with any values passed to it. i.e. for the following script called show_message:
Code:
#!/bin/ksh 
print $1

called like this:
Code:
show_message "hello world!"

The actual command line run by the system would be:
Code:
/bin/ksh show_message "hello world!"

The command after the #! does not have to be a shell either. Try this script:
Code:
#!/bin/ls -l

or this:
Code:
#!/bin/rm
print This will not show because the script is deleted on the first line

This User Gave Thanks to gary_w For This Post:
# 7  
Old 08-30-2011
Quote:
Originally Posted by Dev_Dev
Hi,
2) I'm using bash shell, for this, can I give it as #!/bin/sh
No, do not do that. If this is a script that you wish to truly run using the bash shell, use #!/bin/bash. The practice that arose in the Linux community of using #!/bin/sh to mean bash is simply a bad practice.

Last edited by fpmurphy; 08-30-2011 at 11:46 AM..
This User Gave Thanks to fpmurphy For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. Shell Programming and Scripting

/usr/bin/ksh -E

I saw one script using the first line as below /usr/bin/ksh -E I have used -x for debug but couldn't find what is this -E option for ? Pls let me know what is this -E used for Thanks RL (1 Reply)
Discussion started by: reldb
1 Replies

3. UNIX for Dummies Questions & Answers

Memory usage per user,percent usage,sytem time in ksh

Let's say i have 20 users logged on Server. How can I know how much memory percent used each of them is using with system time in each user? (2 Replies)
Discussion started by: roy1912
2 Replies

4. Shell Programming and Scripting

meaning of #!/bin/ksh -p

:b:HI Friends, Can you help me understand -p option with /usr/bin/ksh shell interpreter ? Thanks, Panditt (1 Reply)
Discussion started by: deshaipet
1 Replies

5. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

6. Shell Programming and Scripting

/bin/sh and /bin/ksh problem

we have a shell script that we are using in KSH if ]; then _IFS=$IFS IFS=: and it's failing on /bin/sh . Is there a simple way to modify it to work on both . ( not with awk) Thanks in adv (3 Replies)
Discussion started by: talashil
3 Replies

7. Shell Programming and Scripting

#!/bin/sh and #!/bin/ksh

Hi All, I have a shell (#!/bin/sh) with below piece of code: if ! then echo Staging table ABC_INT_TAB is not present in the schema >> $OUTPUT fi Shell is throwning below error and continue to work even after this error... (3 Replies)
Discussion started by: bhush782003
3 Replies

8. Shell Programming and Scripting

#!/bin/ksh -e

Can you please tell me what the command "#!/bin/ksh -e" means? I tried running a ksh script with "#!/bin/ksh -e" as starting line, and with "#!/bin/ksh" as starting line - they behave differently.. Thanks! Ramya (2 Replies)
Discussion started by: ramsi_ece
2 Replies

9. Shell Programming and Scripting

#!/bin/ksh

Hi, I wrote scripting to perform some jobs. (eg, run_job) Everything works ok when i tested it on my side. I execute the run_job manually and it works perfectly ok. When my administrator try to run it using a scheduler job. He encountered problem of running it. He said it might be due to... (1 Reply)
Discussion started by: maldini
1 Replies

10. Shell Programming and Scripting

#!/bin/ksh

Hi. What does this command do in the shell script? #!/bin/ksh I have some scripts which do not run if this line is removed. First I thought it is comment but I think it sets up korn as shell. Sanjay (2 Replies)
Discussion started by: sanjay_g
2 Replies
Login or Register to Ask a Question