I'm trying to insert an argument in the middle of a command with "$@"
for learning purposes. I don't know if that's optimal, but it's what I've been trying to do. This is what I have: when I run test.sh foo
it runs echo "$@" bar
which I was hoping would print foo bar
. Instead, it's printing bar foo
. I don't know neither if that's expected behavior nor what I should do instead.
test.sh foo
# runs
echo "$@" bar
# which is printing
bar foo
Edit: I had simplified the context and was in reality trying to use "$@"
in an alias.
test.sh
actually contain? If it really containedecho "$@" bar
, the output of running./test.sh foo
would befoo bar
. Note thattest.sh foo
doesn't look fortest.sh
in the current directory unless you've added.
toPATH
. Maybe you have anothertest.sh
somewhere else and you're running that? – Gilles 'SO- stop being evil' Jul 28 '21 at 21:51test='echo "$@" bar'
and I runtest foo
in a terminal, it printsbar foo
. – matticebox Jul 28 '21 at 21:55$@
, just whatever you stick after the alias name ends up at after the expansion, so you end up withecho "$@" bar foo
. – ilkkachu Jul 28 '21 at 22:00