Reputation: 4140
I expect
set -- "a b"
to set $1 = "a"
and $2 = "b"
, but instead it's setting $1 = "a b"
and $2 = ""
what gives?
Upvotes: 0
Views: 77
Reputation: 601361
The double quotes indicate that "a b"
should be treated as a single parameter. Use
set -- a b
to treat them as two parameters.
Edit in response to your comment: Like this?
$ a="a b"
$ set -- $a
$ echo $1
a
$ echo $2
b
Upvotes: 3
Reputation: 399703
A quoted string is a single "word", so you simply need:
$ set -- "a" "b"
Upvotes: 0