bin
bin copied to clipboard
I think you made a mistake in `english_words`
Maybe that's the behaviour you want, but I think you might have scripted this wrong.
#! /bin/sh
WORDS=$XDG_DATA_HOME/dicen.txt
[ -n "$@" ] && grep -E "$@" "$WORDS"
If you run this script with more than one argument, e.g. english_words hello hi
, "$@"
will get expanded to 'hello' 'hi'
and grep will treat hello
as the ERE and hi
as the name of a file to search into before searching in "$WORDS"
.
If you want to search in "$WORDS"
for hello hi
(i.e. the arguments form a single ERE by getting joined with
) in that case, you can use "$*"
, instead of "$@"
, which will expand to 'hello hi'
, i.e.:
#! /bin/sh
WORDS="$XDG_DATA_HOME/dicen.txt"
[ -n "$*" ] && grep -E "$*" "$WORDS"
If you want to search in "$WORDS"
for hello
and for hi
as if they were two distinct ERE, you can use this solution:
#! /bin/sh
WORDS="$XDG_DATA_HOME/dicen.txt"
for arg in "$@"; do
grep -E "$arg" "$WORDS"
done
You could also just only use the first argument:
#! /bin/sh
WORDS="$XDG_DATA_HOME/dicen.txt"
[ -n "$1" ] && grep -E "$1" "$WORDS"