Hi guys!
I feel absolutely terrible writing this, seeing as I don’t have a Stackoverflow account so cannot ask there, nor do I want to, to b e honest. I’d rather struggle on my own, which would probably lead to me giving up.
Anyway, I’m trying my hand at bash
scripting for the first time ever. I’ve only done CSS, PHP, and Javascript/ES 6 up until last week.
Now, my question is this:
When I run this grep
command in the terminal, it works as expected:
grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words
I can even pipe, |
, the results to refine it:
grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words | grep -v '[omens]' | fgrep 'a' | fgrep 'c' | fgrep 'k'
And everything works like a charm.
However, when I put it in a bash
script, it gives me the following error:
grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words | grep -v '[omens]' | fgrep 'a' | fgrep 'c' | fgrep 'k'
[...]
line 155: grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words | grep: No such file or director
I’ve noticed that is seems Manjaro aliases the grep
command, because I coouldn’t find an alias in one of my own config files, yet:
$ which grep
grep: aliased to grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}
Which led me to trying /usr/bin/grep
instead of grep
in the commands above:
/usr/bin/grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words | /usr/bin/grep -v '[omens]' | /usr/bin/fgrep 'a' | /usr/bin/fgrep 'c' | fgrep 'k'
But the output remains the same:
[...]
line 155: /usr/bin/grep '^w[a-z][a-z][a-z][a-z]$' /usr/share/dict/words | /usr/bin/grep: No such file or directory
Which leads me to ask, if there is a special way to call grep
from a script, vs. calling grep
from the CLI. And I’m presuming the same would be the case for fgrep
.
If my question shouldn’t be here, just tell me and feel welcome to remove it then.