Using wildcards in bash if statement
10,346
You can use double square brackets [[
and ]]
without use of quotes on matching pattern for glob support in BASH:
[[ "$EXECNAME" = -* ]] && echo "error: invalid executable name"
Related videos on Youtube
Author by
Rami Chaouki
Updated on June 26, 2022Comments
-
Rami Chaouki 6 months
I wrote the following code in the bash shell. It's supposed to take the positional parameter, and if it starts with a dash "-", it's supposed to input an error message.
But for some reason, the if statement always gets skipped. It only functions if I literally input -*
I get the impression that the fix has something to do with the "$".
Here is a snippet of the code:
EXECNAME=$1 if [ "$EXECNAME" = "-*" ]; then echo "error: invalid executable name" fi