Unknown test operator

O/S solaris 9
shell ksh

if [ ! `uptime | grep day` ]
then 
  chk_op[0]="WARNING...reboot within the last 24hrs, restarted at `who -r | awk '{print $4$5"@"$6}'`" ; 
else
   if [ `uptime | awk '{print$3}'` -ge 100 ] ; 
   then  
   last_reboot1=`who -b | awk '{print $4" "$5" "$6}'`
   last_reboot2='..OK..'`uptime | awk '{print$3" "$4}'`
   chk_op[0]="last rebooted on ${last_reboot1} ${last_reboot2}"
   fi
fi

The following is received when executing the code:
ksh: up: unknown test operator

Try replacing if [ ! `uptime | grep day` ] with

if ! [ `uptime | grep -q day` ]
1 Like

And if possible, replace all back tics `` with parentheses $()
if ! [ $(uptime | grep -q day) ]

1 Like

dumb question, but what's the difference between the back quotes and parentheses?

The backticks have been deprecated in favor of $() for command substitution because $() can easily nest within itself as in $(echo foo$(echo bar)). There are also minor differences such as how backslashes are parsed in the backticks version.
Eks
echo "hello1-`echo hello2-\`echo hello3-\\\`echo hello4\\\`\``"
vs
echo "hello1-$(echo hello2-$(echo hello3-$(echo hello4)))"

Its also hard do see difference between ' and `

1 Like