I think you're doing the right thing, but the way that you're testing that
syntax isn't right. $@
will give you access to the arguments passed into your
script, but your command, PUSH #1 #2 #3 #4 | echo $2
has two problems. First
of all, the first octothorpe is starting a line comment. you are running PUSH
followed by the bash comment, #1 #2...
. Second, in the scope of this command,
$@
will reference the argument passed into this shell session, not the
argument passed into the command before it. To test this syntax correctly, you
need to use it in the script itself, like this:
- ❯❯❯ cat push.sh
#!/bin/bash
echo $@
- ❯❯❯ ./push.sh one two three
one two three
Or even more succinctly,
- ❯❯❯ bash -c 'echo $@' here are some args
are some args