I don't understand why this if statement is giving an error saying:
Using too many arguments
if [ $file == 'Metro[0-9]*' ] -o [ $file == 'Store[0-9]*' ]
echo "$file"
I literally used every combination of parentheses thinking that there might be a mistake but nothing changed. The interesting thing is, condition works if I just use one of the conditions and erase the other. So I assume there is something wrong with using the -o or parentheses...
There is no shell operator -o, you seem to be looking for
if [[ $file == 'Metro'[0-9]* || $file == 'Store'[0-9]* ]]; then
echo "$file"
fi
which is of course somewhat more succinctly and portably written
case $file in 'Metro'[0-9]* | 'Store'[0-9]*) echo "$file";; esac
Notice the multiple changes in quoting: wildcards mustn't be inside quotes if you want them expanded, and the file name should generally be inside double quotes (though it's not necessary after [[ or case).
Notice also the change to [[ which is not a POSIX sh command -- the first alternative above is specific to Bash / Ksh / other "modern" extended shells. The POSIX [ (aka test) doesn't have a simple way to check if a file matches an arbitrary wildcard expression. Indicentally, Bash also supports if [ condition1 -o condition2 ] but that isn't portable, either, so in a way the worst of two worlds.
if condition is missing then and fi.-o operator does not exist, but you can use || to represent OR.=~ operator to compare a string against a regex.So you can write your condition like this:
if [[ "$file" =~ (Metro|Store)[0-9]* ]] ; then
echo "$file"
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With