Skip to content

What does it mean to both append and prepend a value to a variable? #8523

Closed Answered by faho
Pound-Hash asked this question in Q&A
Discussion options

You must be logged in to vote

The simplest way to figure this out is to just try it:

> set foo middle
> set --append --prepend foo 1 2 3
> echo $foo
1 2 3 middle 1 2 3

So it simply takes the values it is supposed to add, adds them to the beginning and adds the same values, in the same order, to the end.

This is equivalent to

set foo 1 2 3 $foo 1 2 3

Is this super useful? Probably not. But there was no real reason to forbid it, it's consistent, so it's allowed.

I prefer to answer the question instead of letting it stay around or deleting it - https://xkcd.com/979/.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by faho
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants