Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Meaning of script with echo, -d, -f1, -f2 Post 302889244 by bakunin on Wednesday 19th of February 2014 02:05:14 PM
Old 02-19-2014
Quote:
Originally Posted by DK2014
I am a new learner of Unix & need to understand below script as start up,

Can anyone explain the meaning of each line listed below.
First off: you shouldn't, as a beginner, even look at this script: it is very poorly written and if it really does what it is supposed to do this is out of coincidence rather than planned.

Code:
#!/usr/bin/ksh

use this shell (KornShell) as commando processor

Code:
PARAMS=$1

This is supposed to put the first parameter passed on command line into the variable "PARAMS", but if this parameters contains blanks this line will fail because the variable declaration is not quoted. Correct would be:

Code:
PARAMS="$1"

Code:
#echo "parms passed is $PARAMS @"

This is a comment (like everything after "#" until the end of the line).

Code:
STATUS=`echo ${PARAMS} | cut -d: -f1`

This (and a lot of similar lines) is a waste of time and system resources. It executes a command (echo $PARAMS | cut -d: -f1) in a subshell ("`...`") and stuffs the output of this command into a variable STATUS. First, the backquotes used for the subshell are deprecated and shouldn't be used any more. Second, it too is not quoted like the first line and therefore prone to failure. To make the construct syntactically correct it should read:

Code:
STATUS="$(echo ${PARAMS} | cut -d: -f1)"

But the whole thing is unnecessary altogether, because what this is supposed to do - cut the content of "$PARAMS" from the beginning to the first ":"
- can be done without a subshell by simple parameter expansion:

Code:
STATUS="${PARAMS%%:*}"

The same goes for all the other lines analogously.

Code:
while [ $EMAIL_ADDRESS > '' ]
do
done

This is simply a syntax error, because [ $EMAIL_ADDRESS > '' ] won't work. Even if it would work, using "$EMAIL_ADDRESS" unquoted would cause a runtime error if the variable contains nothing. If it is supposed to mean "as long as "$EMAIL_ADDRESS" is not empty" (which is my suspicion) it will have to be written:

Code:
while [ -n "$EMAIL_ADDRESS" ]

Add to this that no attempt at error handling is made, parameters are not checked at all and the script has no output. I suggest you throw away this rubbish and try to write a script yourself. Even as a total beginner you will probably create something better than this.

I hope this helps.

bakunin
This User Gave Thanks to bakunin For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Meaning of this line in script

Can anyone explain me the meaning of line #2 in these lines of shell script: if ; then ${EXPR} " ${MACTIONS } " : ".* ${ACTION} " >/dev/null 2>&1 || die "$USAGE" else Sorry in case this is a trivial thing (I am not an expert in this). (3 Replies)
Discussion started by: radiatejava
3 Replies

2. Shell Programming and Scripting

Using echo to create a script

Hello all, I want to be able to create a script on the fly from another script by echoing lines into a file, but am running into difficulty, as it isn't working right. What am I doing wrong? echo "for i in `grep $FRAME /root_home/powermt.sort.fil |awk '{print $7}'`" > pvtimout_set.sh... (5 Replies)
Discussion started by: LinuxRacr
5 Replies

3. UNIX for Dummies Questions & Answers

meaning of script

hello every one i want to know meaning of following line INST_PARA=$HOME/install/Install.Para SAVEMEDIUM=`awk '$2=="ArchiveSave"{print$4}' $INST_PARA` (4 Replies)
Discussion started by: kaydream
4 Replies

4. Shell Programming and Scripting

echo prints nothing-shell script

could anyone tell me why when i execute the following script, echo returns blank set k = 1 echo $k (9 Replies)
Discussion started by: saman_glorious
9 Replies

5. Shell Programming and Scripting

printf/echo in a second script

This may be little confusing. I have Script1, which pulls data from the system and creates another script(lets say script2). While I run script1 I need to add printf/echo statements for script2, so that when I run script2 I see those statement. eg: script1 765 printf " display frame-$1 timeoffset... (2 Replies)
Discussion started by: miltonrods
2 Replies

6. Shell Programming and Scripting

Whats the meaning of set -e inside the script

Hi, I would like to ask about the meaning or purpose of set -e in the script bash, Does it mean if a wrong command in the script it will close or exit the script without continuation thats what happen if i set it in the terminal. Thanks in advance (3 Replies)
Discussion started by: jao_madn
3 Replies

7. UNIX for Dummies Questions & Answers

Meaning of awk script

what does this mean? awk '!a||a>$1 {a=$1} END {for (i in a) print a,i}' file (6 Replies)
Discussion started by: osama ahmed
6 Replies

8. UNIX for Dummies Questions & Answers

UNIX Script - snipet meaning?

What would the below code snippet mean? my ($_configParam, $_paramValue) = split(/\s*=\s*/, $_, 2); $configParamHash{$_configParam} = $_paramValue; (2 Replies)
Discussion started by: MaKha
2 Replies

9. Shell Programming and Scripting

What is the meaning of ## in UNIX shell script?

Hi All, I am new to unix shell scripting and I was documenting one of the unix script and encountered below statements - for ii in `ls -1rt /oracle/admin/MARSCOPY/ext_files/fpm-ifpm/*.small.txt | tail -1 | awk '{print $1}'` do smallssim=${ii##/oracle/admin/MARSCOPY/ext_files/fpm-ifpm/}... (2 Replies)
Discussion started by: shuklajayb4
2 Replies

10. Shell Programming and Scripting

Meaning of =~ in shell script

Please let me understand the meaning of following line in unix bash scripting .is =~ means not equal to or equal to . if ]; then echo -e "pmcmd startworkflow -sv ${INTSERV} -d ${INFA_DEFAULT_DOMAIN} -uv INFA_DEFAULT_DOMAIN_USER" \ "-pv INFA_DEFAULT_DOMAIN_PASSWORD -usdv... (2 Replies)
Discussion started by: harry00514
2 Replies
All times are GMT -4. The time now is 10:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy