1

I have a task where it says:

grep -n -e "^[[:space:]]" \ 
 -e '#[[:space:]]' $ARG | grep -e include

(after the " \ " the code part is on the bottom line)

What does "#" mean in the grep line

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 1
    As an aside, you should [quotes the variable](https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable) and [avoid uppercase for your private variable names.](https://stackoverflow.com/questions/673055/correct-bash-and-shell-script-variable-capitalization) – tripleee Dec 17 '20 at 17:19

2 Answers2

1

# has no special meaning in regular expressions, it's just matching the character literally. So the first grep matches lines that begin with whitespace or have whitespace after a # character.

They could have used an extended regular expression and matched them both in a single regexp.

grep -E -n '(^|#)[[:space:]]' "$ARG" | grep include
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

The # is trivial; like most other characters in regular expressions, it simply matches itself.

The double -e is actually more interesting here; you can supply more than one search expression by passing the -e option multiple times. (A single -e is rarely useful, though it's necessary if you want to pass in a regular expression which would otherwise look like an option to grep, like -n or, of course, -e.)

tripleee
  • 175,061
  • 34
  • 275
  • 318