Jamie Kitson
Jamie Kitson

Reputation: 4140

My understanding of `set --` wrong?

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

Answers (2)

Sven Marnach
Sven Marnach

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

unwind
unwind

Reputation: 399703

A quoted string is a single "word", so you simply need:

$ set -- "a" "b"

Upvotes: 0

Related Questions