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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What is the function of the following lines at the top of a shell script file: Directory and Script?
# 1  
Old 05-04-2016
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!
# 2  
Old 05-04-2016
Quote:
Originally Posted by remytom
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 01:56 AM..
# 3  
Old 05-04-2016
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 05-04-2016
Quote:
Originally Posted by remytom
.
.
.
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 05:43 AM..
# 5  
Old 05-04-2016
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

3. Shell Programming and Scripting

Script to search every file in a directory and print last few lines

Hi everyone, I need to write a script to search a directory, output the name of a file to an ouput file and print the last few lines of the files to the output file such that I would have something like this: FILE1: LINE LINE LINE FILE2: LINE LINE LINE FILE3: LINE LINE LINE... (2 Replies)
Discussion started by: mojoman
2 Replies

4. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

5. Shell Programming and Scripting

Shell scripting-I need a script which should watch a directory for a file with specific directory

I need a script which should watch a directory for a file with specific directory. If it finds a file in directory, it should search for few specific keyword in the file. if the keyword exists, it should trim string from specific column. The file should be moved to another directory and the a... (8 Replies)
Discussion started by: akashdeepak
8 Replies

6. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

7. Homework & Coursework Questions

Shell Script - (File and Directory)

1. The problem statement, all variables and given/known data: My problem is that when I made up a non-existing directory, it prints out "hiii". It didn't enter the first if statement. It works if my directory exist. 2. Relevant notes: The question is here:... (3 Replies)
Discussion started by: spider-man
3 Replies

8. Homework & Coursework Questions

Shell Script - (file and directory)

The question is here: http://farm9.staticflickr.com/8065/8217767191_2154e64904_b.jpg My problem is that when I made up a non-existing directory, it prints out "hiii". It didn't enter the first if statement. It works if my directory exist. My Work: for fileOrDirectory in $* # all... (1 Reply)
Discussion started by: spider-man
1 Replies

9. Shell Programming and Scripting

Calling a function in cpp file inside shell script

Hi I need to call a function written in a cpp file with arguments inside the shell script..Can anyone help me how to do this:( (1 Reply)
Discussion started by: rkrish
1 Replies

10. Shell Programming and Scripting

extracting function headers in a c/c++ file using shell script

Hi, Is there any way to extract function headers from c and c++ files using a shell script? I tried to do it by reading the C/C++ file line by line and if a line matches a particular pattern (pattern of function header) i extracted it otherwise moved to next line. The problem here is, some... (3 Replies)
Discussion started by: priyadarshini
3 Replies
Login or Register to Ask a Question