'Using grep to check if a variable stored in a file is not undefined or blank
Consider a file called .env containing:
env1=foo
env2=bar
I use grep with a regular expression to confirm there's a line defining env2 with a non-blank value, expecting to get a match.
~$ grep -c -i '^env2=(?!\s*$).+' .env
0
Returns 0 matches... but why? I got a match when I tested the same thing here: https://regexr.com/6g7of
Sanity check:
~$ grep -c -i '^env2=bar' .env
1
To confirm multiline is supported in case I had a doubt.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
