0

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
$
ilkkachu
  • 133,243
  • 15
  • 236
  • 397
haolee
  • 103
  • 4
  • `$@` 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

1 Answers1

0

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.

Ulrich Schwarz
  • 15,669
  • 4
  • 47
  • 58