Skip to main content
added 479 characters in body
Source Link
sourcejedi
  • 53.5k
  • 23
  • 178
  • 336

$ man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solutionThis can be verified by referring to the secret POSIX standard (thoughseriously, they slightly obscure the webpage hoping more people buy print versions).

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html#tag_20_55_14

EXIT STATUS

The following exit values shall be returned:

 0
    One or more lines were selected.
 1
    No lines were selected.
>1
    An error occurred.

example solution

Albeit without trying to detect errors)when "an error occurred":

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

$ man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

$ man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

This can be verified by referring to the secret POSIX standard (seriously, they slightly obscure the webpage hoping more people buy print versions).

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/grep.html#tag_20_55_14

EXIT STATUS

The following exit values shall be returned:

 0
    One or more lines were selected.
 1
    No lines were selected.
>1
    An error occurred.

example solution

Albeit without trying to detect when "an error occurred":

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi
edited body
Source Link
sourcejedi
  • 53.5k
  • 23
  • 178
  • 336

#$ man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

# man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

$ man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi
added 100 characters in body
Source Link
sourcejedi
  • 53.5k
  • 23
  • 178
  • 336

# man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

# man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi

# man grep

/EXIT

EXIT STATUS
   Normally the exit status is 0 if a line is selected, 1 if no lines were
   selected, and 2 if an error occurred.  However, if the -q or --quiet or
   --silent  is  used and a line is selected, the exit status is 0 even if
   an error occurred.

EDIT: hopefully this makes it clear. I know it's a surprise if you weren't looking for this behaviour.

example solution (though without trying to detect errors):

if (uname -s | grep -i darwin >/dev/null); then
  IS_DARWIN=1
fi
Source Link
sourcejedi
  • 53.5k
  • 23
  • 178
  • 336
Loading