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:
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.
To test this script create a file "inputfile", put some lines of text into it and call the script with
which will work. Try
then and it will fail with the error message:
The third parameter must be numeric, you entered erroneous_value.
Thank you for your detailed response. I appreciate your time and it looks like I have a long ways to go before I am going to be able to write effective scripts. Would you be able to recommend textual material I could reference through this learning process ?
Thanks again
Thank you for your detailed response. I appreciate your time and it looks like I have a long ways to go before I am going to be able to write effective scripts. Would you be able to recommend textual material I could reference through this learning process ?
Thanks again
Glad to be of help and: Yes! Get a copy of Barry Rosenbergs "Hands-On ksh93 programming", it is not only full to the brim with information (i use it as my desk-side reference wherever i go) but also a great fun to read. It is by far the best read i ever encountered as an IT-book.
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)
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)
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)
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)
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)
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)
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)