0

I'm trying to make a script that's supposed to tell me which argument stars with a dash. I looked at In Bash, how can I check if a string begins with some value?, but the accepted answer didn't work.

Here is the script:

for var in "$@"
do
    echo "$var"
    if [[ $var == -* ]]
    then
        echo "$var starts with dash"
    fi
done

When I run it I just get this:

~$ ./dash_test.sh -dash no_dash --two -one
-dash
no_dash
--two
-one

That if [[ $var == -* ]] doesn't appear to work, which is what was suggested in that question I linked.

Maxim
  • 335
  • 5
  • 14
  • 1
    Are you sure you are using `bash`? You have no shebang in the script; what happens when you run `bash dash_test.sh -dash no_dash --two -one`? – chepner Mar 22 '22 at 19:41
  • Yep, that's it, I forgot Alpine uses Ash, I think by default – Maxim Mar 22 '22 at 19:43

0 Answers0