The following script can only print -m
but it can't print -n
.
#!/bin/sh
echo $@
$ sh test.sh -m
-m
$ sh test.sh -n
$
The following script can only print -m
but it can't print -n
.
#!/bin/sh
echo $@
$ sh test.sh -m
-m
$ sh test.sh -n
$
That's because -n
is an actual option to echo
. Most tools support --
to mean "there's no more options after this, just arguments", so try if using
echo -- $@
improves the situation.
$@
doesn't print anything, and it deals with-n
just fine, though you should be using"$@"
instead; or maybe"$*"
in this case. – ilkkachu Jul 29 '22 at 04:07