RE: syntax error near unexpected token `then'

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Stuart Stephen wrote:
> Hi,
>

[snip...]
 
> cont() {
>   /root/scripts/continue
>   if[ "$?" == 1 ];
>     then
>     echo "Continuing process.";
>   else
>     exit 1;
>   fi
> }

Try the following syntax. Note the spaces between the []'s

cont() {
  /root/scripts/continue
  if [ "$?" == 1 ] ;
    then
      echo "Continuing process.";
    else
      exit 1;
  fi
}

Also, (I'm being anal here) but in your example, it looks as though your
trying to test the exit status '$?' from /root/scripts/continue. Unless your
overiding this value, the exit status return value is an integer, not a
string. With this in mind, consider testing for an integer (-eq), not a
string (==). Example:

if [ $? -eq 1 ] ;

See "man bash" under the "CONDITIONAL EXPRESSIONS" and "EXIT STATUS"
sections.

Steve Cowles


-- 
redhat-list mailing list
unsubscribe mailto:redhat-list-request@xxxxxxxxxx?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list

[Index of Archives]     [CentOS]     [Kernel Development]     [PAM]     [Fedora Users]     [Red Hat Development]     [Big List of Linux Books]     [Linux Admin]     [Gimp]     [Asterisk PBX]     [Yosemite News]     [Red Hat Crash Utility]


  Powered by Linux