-3

I would like to know what -eq does in a bash script (as in the below example):

LINES=`ps -p $PID`
    PIDRET=$?
    if [ $PIDRET -eq 0 ];
    then
        export PID
        return 0;
    fi
    rm -f "$CATALINA_PID" 
eabates
  • 840
  • 1
  • 8
  • 21

1 Answers1

-4

-eq in bash means exactly the same as == - it perfroms logical comparison of two things checking if they're equal. You can find more about operators in bash in documentation: http://www.tldp.org/LDP/abs/html/comparison-ops.html

kiler129
  • 1,003
  • 2
  • 9
  • 21
  • 3
    The link you posted states that `-eq` and `==` are *not* the same. – Robert Nov 04 '16 at 20:02
  • In general, the ABS is a very poor reference -- think of it as being to bash what W3Schools is to JavaScript; it very frequently showcases bad practices in its examples. If not using the [official manual](https://www.gnu.org/software/bash/manual/html_node/Bash-Conditional-Expressions.html) or [the POSIX specification](http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html), consider making a habit of using either [the bash-hackers wiki](http://wiki.bash-hackers.org/commands/classictest) or [the Wooledge BashGuide](http://mywiki.wooledge.org/BashGuide/TestsAndConditionals). – Charles Duffy Nov 04 '16 at 20:05
  • 1
    Moreover, `==` shouldn't be used in `[ ]` at all: `[` is a POSIX-specified command, but the specification's only string comparison operator is `=`, **not** `==`; the latter is a nonportable extension. If you want to use nonportable extensions, use `[[ ]]` instead of `[ ]`, rather than writing code that *looks* like it's POSIX-compliant but isn't. – Charles Duffy Nov 04 '16 at 20:11