2

I'm not sure what the following line does in a bash script:

if echo $line | grep -F = &>/dev/null
then
  ...

I know &>/dev/null is short for >/dev/null 2>&1, I'm not sure, however, what the = is for and I cannot find any explanation.

  • It checks is there = symbol in line variable – Costas Jan 25 '16 at 23:44
  • It could be (perhaps) more clearly written as if [[ $line == *"="* ]]; then ... – glenn jackman Jan 26 '16 at 0:11
3

From man grep

-F, --fixed-strings
       Interpret PATTERN as a  list  of  fixed  strings,  separated  by
       newlines,  any  of  which is to be matched.  (-F is specified by
       POSIX.)

So it's just checking for the presence of = as a literal string in $line

  • 1
    Not in $line, in the output of echo $line which could be completely different. As echo and the slit+glob operator are used. – Stéphane Chazelas Jan 26 '16 at 13:29
1

It does:

case $line in 
(*=*) : this would be the then block
;; 
(*)   : maybe an else\?
;;
esac

...only not very well, or nearly as quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.