Why do a unix script starts with a comment?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Why do a unix script starts with a comment?
# 1  
Old 04-12-2010
Why do a unix script starts with a comment?

For eg:

#!/usr/bin/ksh

<remaining code goes here>
..
..


Does the compiler ignores that?

Thanks
# 2  
Old 04-12-2010
The "shebang" line (as it is known) is a clear statement about which program you want to interpret the following lines. It is actioned by the shell even though it appears to be a comment line. The shebang line could be a shell, awk, perl or whatever. It must be the first line of the script.

The shebang line is optional and if not present your script will be interpreted by the default shell for your environment. This can create anomalies if you have a script which is common to more than one enviroment (e.g. user and cron).

It is good working practice to have the shebang line.
# 3  
Old 04-12-2010
It's no comment, it's the shebang, telling the system what interpreter to run this script with (ksh/bash/csh/perl/python/ruby/...)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to write a shell script that starts one, then kills it, then starts another?

This is on a CentOS box, I have two scripts that need to run in order. I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours (that I specify of course), and then calls the second script (they can't run simultaneously) which... (3 Replies)
Discussion started by: btramer
3 Replies

2. Homework & Coursework Questions

When I run the script, the cursor starts on the wrong line?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: It's a shell script using a looping logic, trap, tput, if, while. Most of the scripts in this book aren't written... (2 Replies)
Discussion started by: ckleinholz
2 Replies

3. UNIX for Advanced & Expert Users

Script to rename file that was generated today and which starts with date

hello, can someone please suggest a script to rename a file that was generated today and filename that being generated daily starts with date, its a xml file. here is example. # find . -type f -mtime -1 ./20130529_4995733057260357019.xml # this finename should be renamed to this format.... (6 Replies)
Discussion started by: bobby320
6 Replies

4. Shell Programming and Scripting

Removing the sas comment line using UNIX

I have tried a lot, Need your help guys. SAS Program: data one ; /* Data step */ Input name $; /*Dec variables*/ I want to remove the commented part(/* Data step */) alone. I have tried using sed command but it is deleting the entire line itself. i need unix command to separate this and... (6 Replies)
Discussion started by: saaisiva
6 Replies

5. Shell Programming and Scripting

Detect if script starts from queue

Dear community, what I'm try to do is deny users to run a script without parameters from command bash, but the same script should run without parameters only from crontab. Example runs by crontab:*/5 * * * * /tmp/script.sh Here the normal execution starts every 5 minutes Example #1 runs by... (16 Replies)
Discussion started by: Lord Spectre
16 Replies

6. Shell Programming and Scripting

Start script when a user starts a remote session

Howdy, I'm fairly new at bash scripting, but (for some reason) I've been tasked with building a bastion server and logging all (ssh/telnet) remote activity. Each session must create a unique log file - the name of each file must include the user ID, the connection method (ssh/telnet), the name... (2 Replies)
Discussion started by: kilo90
2 Replies

7. Shell Programming and Scripting

Comment utiliser les commandes shell unix sur vista

1) Comment utiliser les commandes shelll unix pour recherche sur windows vista, est-ce possible et dans ce cas comment 2) comment exécuter un .ksh ou .bat sous putty, j'ai essayé mais je reçois le message ksh: ./: 0403-006 Execute permission denied. lors de la commande ./ testx Merci d'avance (5 Replies)
Discussion started by: infosuni0309
5 Replies

8. Shell Programming and Scripting

Killing a process within 5 min it starts in Unix using perl

Hi All, I have to kill a program whose pid, i will be getting. Multiple processes will be getting started by my script of same kind in a series. So for after each call to a process i need to write a command or script which can kill the process if it takes more than 5min. In this i will... (3 Replies)
Discussion started by: nishank.jain
3 Replies

9. What is on Your Mind?

Line 2238 Unix V6 Comment: You are not expected to understand this.

Here is the famous line 2238 of Unix V6 which is part of some of the most delicate parts of the kernel, context switching. This comment received huge publicity and just may be the the most famous source code comment in computing history. 2230 /* 2231 * If the new process paused because it... (0 Replies)
Discussion started by: Neo
0 Replies

10. Shell Programming and Scripting

how to comment multiple lines in unix

hi all, please help me how to comment multiple lines in unix script. thanks in advance --bali (3 Replies)
Discussion started by: balireddy_77
3 Replies
Login or Register to Ask a Question