-1

Per the fish shell documentation for the set command:

append: causes the values to be appended to the current set of values for the variable. This can be used with --prepend to both append and prepend at the same time.

prepend: causes the values to be prepended to the current set of values for the variable. This can be used with --append to both append and prepend at the same time.

In quotidian English, append means to add, and prepend means to add at the beginning. Clearly, these meanings don't apply to fish (or to computers in general?), for it's redundant to say that we can both add x to y while also adding x to the beginning of y. If we can do the latter, then we can do the former. That is to say, by doing the latter, we do the former. If it's senseless to say that I am both running a race from the starting line and also running a race, then it's senseless to say that I am both prepending some data and also appending that data.

So, what do these terms mean to fish (or in the world of software development)? What are the implications for doing one over the other? And what does it mean to explicitly do both?

0

2 Answers 2

3

Just like it says, it both appends and prepends if both options are given

$ set list 1 2 3
$ set -S list
$list: set in global scope, unexported, with 3 elements
$list[1]: |1|
$list[2]: |2|
$list[3]: |3|
$ set --append --prepend list 4 5 6
$ set -S list
$list: set in global scope, unexported, with 9 elements
$list[1]: |4|
$list[2]: |5|
$list[3]: |6|
$list[4]: |1|
$list[5]: |2|
$list[6]: |3|
$list[7]: |4|
$list[8]: |5|
$list[9]: |6|
1

append: Add something to the end.
prepend: Add something to the beginning.

What you're adding to and what something is depends on context. Consider, for example, a list of integers:

[1, 2, 3]

If I append 4 (the something), then I get:

[1, 2, 3, 4]
          ^

If I then prepend 5 (again, the something), I get:

[5, 1, 2, 3, 4]
 ^

Another context where you might see this is strings. Consider, for example, a string:

"abc"

If I append d, then I get:

"abcd"
    ^

If I then prepend e, I get:

"eabcd"
 ^

If I want to both append and prepend an element, then I apply both operations with the same element. For example, say I want to both append and prepend f, I'd get:

"feabcdf"
 ^     ^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.