Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

What is the function of the following lines at the top of a shell script file: Directory and Script?

Shell Programming and Scripting


Tags
shell bash ksh, shell script, shell script commands

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-04-2016   -   Original Discussion by remytom
remytom's Unix or Linux Image
remytom remytom is offline
Registered User
 
Join Date: May 2016
Last Activity: 4 May 2016, 4:17 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
What is the function of the following lines at the top of a shell script file: Directory and Script?

The file starts like this:



Code:
Directory: <path to the script>
Script: <script fife name>

#!bin/ksh

##Comments

<actual script>

What is the use of the first two lines in the script? What if I save the file without them? What will be the effect? They are not comments. Im very new to this, please help!
Sponsored Links
    #2  
Old Unix and Linux 05-04-2016   -   Original Discussion by remytom
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 13 March 2018, 11:04 PM EDT
Posts: 1,713
Thanks: 49
Thanked 663 Times in 619 Posts
Quote:
Originally Posted by remytom View Post
The file starts like this:



Code:
Directory: <path to the script>
Script: <script fife name>

#!bin/ksh

##Comments

<actual script>

What is the use of the first two lines in the script? What if I save the file without them? What will be the effect? They are not comments. Im very new to this, please help!
The first line of a script should be the shebang #! which it says what program is supposed to run the script when you make the file executable and run it as ./script.sh

However the script can be run as:
ksh script.sh

If you remove the shebang that's the only option you have.
Anything that starts with just a # (except the #!, when is the first line) will be ignored as commands. They are just human readable comments.

I am assuming that the following does not exist in your actual script, since that will be incorrect.


Code:
Directory: <path to the script>
Script: <script fife name>

Note that your #!bin/ksh should be #!/bin/ksh if your ksh shell lives there.

Last edited by Aia; 05-04-2016 at 12:56 AM..
Sponsored Links
    #3  
Old Unix and Linux 05-04-2016   -   Original Discussion by remytom
remytom's Unix or Linux Image
remytom remytom is offline
Registered User
 
Join Date: May 2016
Last Activity: 4 May 2016, 4:17 AM EDT
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you!

Thank you for the quick reply. I have removed these lines from my code. But I see working scripts which have them. Its strange though, because I do get the error of command not found for these lines.

Thanks a lot!
    #4  
Old Unix and Linux 05-04-2016   -   Original Discussion by remytom
RudiC's Unix or Linux Image
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 21 April 2018, 11:23 AM EDT
Location: Aachen, Germany
Posts: 12,504
Thanks: 401
Thanked 3,877 Times in 3,564 Posts
Quote:
Originally Posted by remytom View Post
.
.
.
Its strange though, because I do get the error of command not found for these lines.
.
.
.
No surprise as these "commands" really don't exist. Didn't this error msgs make you suspicious?

Last edited by RudiC; 05-04-2016 at 04:43 AM..
Sponsored Links
    #5  
Old Unix and Linux 05-04-2016   -   Original Discussion by remytom
Don Cragun's Unix or Linux Image
Don Cragun Don Cragun is offline Forum Staff  
Administrator
 
Join Date: Jul 2012
Last Activity: 21 April 2018, 3:15 AM EDT
Location: San Jose, CA, USA
Posts: 11,207
Thanks: 633
Thanked 3,903 Times in 3,341 Posts
I believe that Directory: and Script: may be keywords in ksh93 used for creating libraries of scripts that can be loaded as shell built-ins.

Although in bash the command line:


Code:
Directory: date

will give you a diagnostic similar to:


Code:
bash: Directory:: command not found

that same command (and:


Code:
Script: date

or:


Code:
name: date

for any other name) in ksh93 (at least the Korn shell on OS X with version information: sh (AT&T Research) 93u+ 2012-08-01) will print the current date and time.

Note that the standards specify that the name of a utility (and the name of a variable and several other names) is "a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit." So the standards allow shells to produce unspecified results when a utility name contains a colon. (It appears that ksh93 does assign some meaning to names ending with a colon [names containing a colon other than as the last character don't seem to be treated specially], but I haven't found any description of exactly what those results are intended to be in the man page.)

Some of you who have been around as long as I have may also remember that some early shells (pre-Bourne) used a string ending with a colon appearing at the start of a line as a label that could be jumped to with a:


Code:
goto label

command. I believe the Mashey shell was the 1st to deprecate the goto command and the Bourne shell was the first shell that did not include a goto command.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Shell Script function to use script name for log file output SIMMS7400 Shell Programming and Scripting 11 04-03-2016 06:01 PM
Shell scripting-I need a script which should watch a directory for a file with specific directory akashdeepak Shell Programming and Scripting 8 08-26-2014 05:05 PM
Shell Script - (file and directory) spider-man Homework & Coursework Questions 1 11-25-2012 05:06 PM
Calling a function in cpp file inside shell script rkrish Shell Programming and Scripting 1 06-19-2012 09:06 PM
extracting function headers in a c/c++ file using shell script priyadarshini Shell Programming and Scripting 3 06-24-2009 10:31 AM



All times are GMT -4. The time now is 11:39 AM.