Operating System - HP-UX
1752803 Members
5455 Online
108789 Solutions
New Discussion юеВ

Re: Scripting clarification

 
Omprakash_2
Frequent Advisor

Re: Scripting clarification

Hi Manikandan,

As you said i have edit as below, i am getting output as well. But if i edit script1 without the word "Yes". Its provide me the same output.

# pg script1
#!/usr/bin/sh
server1
server2
server3
server4
server5
server6
(EOF):
--------------------------------------------
# pg script2
#!/usr/bin/sh
#ans='sed -n'5,5p'script1'
if test 'cat /script1'NR==5{print$0}="Yes"
then
echo "Your current Location"
pwd
date
else
echo "stop"
fi

(EOF):
--------------------------------------------
OUTPUT:
-------
# ./script2
Your current Location
/
Fri Apr 3 14:15:22 IST 2009

-------------------------------------------
T G Manikandan
Honored Contributor

Re: Scripting clarification

`cat /tmp/a.sh|awk 'NR==5 {print $0}'` = "yes"

Please check the quote before cat and after $0}

These quotes are command substitution quotes and not normal single quote.
T G Manikandan
Honored Contributor

Re: Scripting clarification

I dont see awk statement in your copied version and no spaces too, it should be

if test `cat /script1 |awk 'NR==5 {print$0}'` = "Yes"
T G Manikandan
Honored Contributor

Re: Scripting clarification

Attaching script2
Omprakash_2
Frequent Advisor

Re: Scripting clarification

Hi Manikandan,

Problem fixed because of you, Thanks a ton its working fine !!!
Omprakash_2
Frequent Advisor

Re: Scripting clarification

Thanks Suraj/Frank & Manikandan...
T G Manikandan
Honored Contributor

Re: Scripting clarification

wow, it fixed but you give 1 point?
Dennis Handly
Acclaimed Contributor

Re: Scripting clarification

./script2[3]: [sed: not found.

This says the word "[sed" is not found. You seem to have some missing spaces.

ans='sed -n'5,5p'script1'
if [$ans=="Yes"]

The first problem is the attempted use (as TG said) of archaic ``, instead of the easy to read $()
ans=$(sed -n '5,5p' script1)
Then you are missing that space (as TG said):
if [ "$ans" = "Yes" ]; then

# pg script1
#!/usr/bin/sh

This isn't a script, it is a data file.

>TG: if test `cat /script1 |awk 'NR==5 {print$0}'` = "Yes"

No need for evil cat or test, or ``:
if [ "$(awk 'NR==5 {print $0; exit}' script1)" = "Yes" ]; then
T G Manikandan
Honored Contributor

Re: Scripting clarification

Thanks Dennis for those corrections.