Sponsored Content
Full Discussion: significance of statement
Top Forums UNIX for Dummies Questions & Answers significance of statement Post 302168712 by bakunin on Tuesday 19th of February 2008 08:07:10 AM
Old 02-19-2008
The script gets several parameters on the command line, the first one is "$1" inside the script, the second one "$2", etc. Here is an example for that mechanism:

Code:
user@machine:/~ # cat showparams.ksh

#! /usr/bin/ksh

print - "1st parameter: $1"
print - "2nd parameter: $2"
print - "3rd parameter: $3"
print - "4th parameter: $4"
exit 0

user@machine:/~ # ./showparams.ksh a b c d
1st parameter: a
2nd parameter: b
3rd parameter: c
4th parameter: d

By the way (this is not answering your question, but probably not wasted on a scripting beginner either): it is NOT good programming style to use these parameters as they are! Usually these parameters have some "meaning" in your script and it is better to define some variables, check the parameters if they make sense and then copy the commandline parameters to these variables and use them.

Here is an example. The script does nothing useful, just takes three parameters, an input file, an output file and a number and copies the content of the input file to the output file prepending every line with "Value was <number> ;". Its purpose is just to show hoe to first check and then subsequently use parameters passed on the command line.

Code:
#! /usr/bin/ksh

typeset    fInput="$1"            # file with the data to work on
typeset    fOutput="$2"           # file to store results to
typeset -i iSomeValue=0           # some numerical value

# before we use the parameters we test if they make sense:

                                  # make sure input is readable
if [ ! -r "$fInput" ] ; then      
     print -u2 "File $fInput is not readable or does not exist."
     exit 1
fi   

touch "$fOutput"                  # make sure output is writable
if [ $? -gt 0 ] ; then
     print -u2 "File $fOutput is not writeable."
     exit 1
fi
     
                                  # make sure $3 is really an integer
if [ -z "$(print - "$3" | sed 's/[0-9]//g')" ] ; then
     print -u2 "The third parameter must be integer, you entered $3"
     exit 1
else
     iSomeValue=$3
fi

# .... here goes the rest of your code ...

cat $fInput | while read chLine ; do
     print "Value was $iSomeValue ; $chLine" >> $fOutput
done

exit 0

To test this script create a file "inputfile", put some lines of text into it and call the script with

Code:
./script.ksh inputfile outputfile 25

which will work. Try

Code:
./script.ksh inputfile outputfile erroneous_value

then and it will fail with the error message:

The third parameter must be numeric, you entered erroneous_value.

I hope this helps.

bakunin
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

what the significance of ~

what does this symbol ~ represent in unix for example.... If i create directories called personal and lab and lab5 and the command chmod 776~/lab5 is issued. What results would i expect to get. basically i know that chmod 776 would prevent others from executing the files in the directory but... (2 Replies)
Discussion started by: BigTool4u2
2 Replies

2. Shell Programming and Scripting

what is the significance of braces and spaces???

Hi , i have few doubts about the braces and spaces which are quite often used: for instance: when i try the belo command it will not work export variable= cat filename rather when i try the cat command without any space it works fine export variable=cat filename and... (3 Replies)
Discussion started by: ahmedwaseem2000
3 Replies

3. Shell Programming and Scripting

What is the significance of . / ?

Many scripts are executed in the following way. . /scriptname Even when the file does not have execute permission, it can be executed this way. How does this work? (6 Replies)
Discussion started by: krishmaths
6 Replies

4. Solaris

significance of library locations in solaris8...please help

this post is related to the arrangements of libraries in a solaris-8 distribution. i want to build external packages on solaris-8 i need to know why libraries are scattered in a solaris distribution among different below mentioned directories, please tell me whats the importance ?? /lib... (3 Replies)
Discussion started by: mobydick
3 Replies

5. AIX

Group significance in mkrole aix 5.3

Hello... I am getting ready to create a bunch of groups for several of our servers all of which are running Aix 5.3. We really want to keep people away from using the root login and as such the systems have been hardened using aixpert and if it is absolutely needed people must su -. There are... (1 Reply)
Discussion started by: dgaixsysadm
1 Replies

6. Shell Programming and Scripting

Significance of '{}' \;

What is the Significance of '{}' \; in UNIX? (2 Replies)
Discussion started by: Shell_Learner
2 Replies

7. Shell Programming and Scripting

Significance of forward slash(/) while specifying a directory

What is the significance of the forward slash(/) while specifying a directory? cp -av /dir/ /opt/ and cp -av /dir /opt Does effectively the same job it seems? (2 Replies)
Discussion started by: proactiveaditya
2 Replies

8. Solaris

significance of pfiles

What is the significance of pfiles? What is the use of it and how and where to use it?:wall: (2 Replies)
Discussion started by: varunksharma87
2 Replies

9. Shell Programming and Scripting

Significance of ':-' while accessing a variable

Hi I was trying to understand what ':-' means when used with variables echo ${x:-10} if Thanks (4 Replies)
Discussion started by: zulfi123786
4 Replies

10. UNIX for Dummies Questions & Answers

Significance of different shells?

I'm taking a LINUX and UNIX class and we are using bash as the shell in terminal. On my mac-book I use zsh only because my professor had a pretty cool start-up file for it. It has benefited me in becoming familiar with different shells. However, I'm having a hard time understanding the purpose... (4 Replies)
Discussion started by: syregnar86
4 Replies
EXECUTE(7)                                                         SQL Commands                                                         EXECUTE(7)

NAME
EXECUTE - execute a prepared statement SYNOPSIS
EXECUTE name [ ( parameter [, ...] ) ] DESCRIPTION
EXECUTE is used to execute a previously prepared statement. Since prepared statements only exist for the duration of a session, the pre- pared statement must have been created by a PREPARE statement executed earlier in the current session. If the PREPARE statement that created the statement specified some parameters, a compatible set of parameters must be passed to the EXECUTE statement, or else an error is raised. Note that (unlike functions) prepared statements are not overloaded based on the type or number of their parameters; the name of a prepared statement must be unique within a database session. For more information on the creation and usage of prepared statements, see PREPARE [prepare(7)]. PARAMETERS
name The name of the prepared statement to execute. parameter The actual value of a parameter to the prepared statement. This must be an expression yielding a value that is compatible with the data type of this parameter, as was determined when the prepared statement was created. OUTPUTS
The command tag returned by EXECUTE is that of the prepared statement, and not EXECUTE. EXAMPLES
Examples are given in the Examples [prepare(7)] section of the PREPARE [prepare(7)] documentation. COMPATIBILITY
The SQL standard includes an EXECUTE statement, but it is only for use in embedded SQL. This version of the EXECUTE statement also uses a somewhat different syntax. SEE ALSO
DEALLOCATE [deallocate(7)], PREPARE [prepare(7)] SQL - Language Statements 2010-05-14 EXECUTE(7)
All times are GMT -4. The time now is 12:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy