if returns "unknown test operator"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if returns "unknown test operator"
# 1  
Old 04-24-2009
if returns "unknown test operator"

Greetings, using ksh on Solaris, I am trying to identify the current version of a package installed on multiple servers using if statement in a precursor to upgrading.
I have searched the forums and have found many hits, reviewed 3 pages and have tried the different variations noted there. Also checked the site, Bourne/Korn Shell Coding Conventions at OpenSolaris.org to validate operators and syntax, yet I am not getting this to work.
I have tried the following variations and all return some error, most commonly:

ksh: 1.11: unknown test operator
no

Am I missing something simple?

Code:
if [ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" = 1.11 ]
then
echo yes
else
echo no
fi
 
if [ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" eq 1.11 ]
then
echo yes
else
echo no
fi
 
if [ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" eq "1.11" ]
then
echo yes
else
echo no
fi
 
if [ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" -eq "1.11" ]
then
echo yes
else
echo no
fi
 
if [[ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" -eq "1.11" ]]
then
echo yes
else
echo no
fi
 
if [ echo "\"`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`\"" -eq "1.11" ]
then
echo yes
else
echo no
fi

# 2  
Old 04-24-2009
"=" is for comparing strings so running a set of commands that pulls out the version number thus:
Code:
if [ "`string of command to get version number`" = "1.11" ]; then

should be okay.
I don't know why you have an echo.

"-eq" compares integer numbers so could not compare 1.11 with anything.

I am not sure of any shell that would accept "eq" instead of "-eq"?
# 3  
Old 04-24-2009
TFM - the echo is just for my precursor test, I will fill with exit or pkgrm and pkgadd based on results.
As for the syntax with = and "1.11", I am still getting the error with the following 2 other attempts:
Code:
if [ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`" = "1.11" ]
then
echo yes
else
echo no
fi

if [ echo "\"`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`\"" = "1.11" ]
then
echo yes
else
echo no
fi

For comparison, here are the results of the separate commands on my test server:
Code:
 $ echo "`pkginfo -x \`pkginfo | grep libiconv | awk '{print $2}'\` | grep sparc | awk '{print $2}'`"
1.11

# 4  
Old 04-24-2009
I figured it out after checking another one of my test using commands. Since I am echo the command results, I actually need to capture the echo as my command and test that. So, more capture the echo command and escape the commands within the echo.
Code:
$ if [ `echo "\`pkginfo -x \\\`pkginfo | grep libiconv | awk '{print $2}'\\\` | grep sparc | awk '{print $2}'\`"` = 1.11 ] ;then echo yes; else echo no;fi
yes

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

What is the significance of sh -s in ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh?

Please can you help me understand the significance of providing arguments under sh -s in > ssh -qtt ${user}@${host} "sh -s "${version}"" < test.sh (4 Replies)
Discussion started by: Sree10
4 Replies

2. Shell Programming and Scripting

Unknown test operator

O/S solaris 9 shell ksh if then chk_op="WARNING...reboot within the last 24hrs, restarted at `who -r | awk '{print $4$5"@"$6}'`" ; else if ; then last_reboot1=`who -b | awk '{print $4" "$5" "$6}'` last_reboot2='..OK..'`uptime | awk '{print$3" "$4}'` ... (4 Replies)
Discussion started by: squrcles
4 Replies

3. Shell Programming and Scripting

Unknown test operator

Hi , Os - Solaris Shell - Ksh I am getting below error in if condition + id + ./om_wf_complete.sh: gid=4081(Infadmn): unknown test operator + exit 1 if ; then touch /home/odwt/1.0.0/out/oworkflow.dat chmod 777 /home/odwt/1.0.0/out/oworkflow.dat elif ; then touch... (8 Replies)
Discussion started by: nag_sathi
8 Replies

4. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

5. Shell Programming and Scripting

error "test: [-d: unary operator expected" very confused.

Im trying to check if a series of directory exists and if not create them, and am having issues. All the instances of test return with the error "test: #!/bin/bash location_Parent=~/Documents/sight_of_sound location_IMG=~/Documents/Sight_of_sound/IMG location_AUD=~/Documents/Sight_of_sound/AUD... (4 Replies)
Discussion started by: orionrush
4 Replies

6. Shell Programming and Scripting

unknown test operator

hi all, i am using the below command in my script if ; then This statement is causing the problme "ScriptName.ksh: XXX-XXX: unknown test operator" could you please suggest me , how can i avoid these messages. Singhal (7 Replies)
Discussion started by: singhald
7 Replies

7. Shell Programming and Scripting

syntax error in shell test: unknown operator

Hi All, can some one figure out the syntax issue here. How to overcome this? #!/bin/sh $ HFR_MAIL=NO $ PRP_MAIL=NO $ MC_MAIL=NO $ if && && ]; then > echo "NO " > else > echo "YES" > fi test: unknown operator NO $ if && && ]; then > echo "NO" > else > echo "YES" >... (4 Replies)
Discussion started by: shellscripter
4 Replies

8. Shell Programming and Scripting

test: unknown operator status

hi I get test: unknown operator status if then echo "OK." return 0 else echo "not ok" 2>&1 exit -1 fi I tried to change "A" with 'A' --> same error I tried to change if , I am getting: (3 Replies)
Discussion started by: melanie_pfefer
3 Replies

9. UNIX for Advanced & Expert Users

unknown test operator

Hi, I have the following shell script : Nbr_BD_Link=0 Nbr_BD_Link=` sqlplus sysadm/${PSWD}@${DB_Name} << EOF | tail -4 | head -1 2>/dev/null set head off feedback off ; select count(*) from dba_db_links ; exit ; EOF ` echo ${Nbr_BD_Link} if ; then ... (4 Replies)
Discussion started by: big123456
4 Replies

10. Shell Programming and Scripting

:0: unknown test operator

I have gotten the script up to this point and it works fine a system but when i copy it to another unix server running solaris 9 as the original one , its gives an error './mon_fs.sh: 0: unknown test operator' . (see script bellow) can the Gurus see to this as i am just a beginner with... (2 Replies)
Discussion started by: ibroxy
2 Replies
Login or Register to Ask a Question