In bash, newline characters are preserved through command substitution:
$ TEST="$(echo 'a
b
c
')" && echo "$TEST"
# →
a
b
c
However, when I try to do the same in fish shell, the newline characters get converted into spaces:
$ set TEST (echo "a
b
c
"); and echo "$TEST"
# →
a b c
How to make fish save the newline characters as newlines?
To give a variable to an external command, it needs to be “exported”. Unlike other shells, fish does not have an export command. Instead, a variable is exported via an option to set , either --export or just -x .
Prompt Tab The "prompt" tab displays the contents of the current fish shell prompt. It allows selection from 17 predefined prompts. To change the prompt, select one and press "Prompt Set!". DANGER: This overwrites ~/.
It does this by adding the components either to $fish_user_paths or directly to $PATH (if the --path switch is given). It is (by default) safe to use fish_add_path in config. fish, or it can be used once, interactively, and the paths will stay in future because of universal variables.
The configuration file runs at every login and is located at ~/. config/fish/config. fish . Adding commands or functions to the file will execute/define them when opening a terminal, similar to .
Conceptually, they are not converted into spaces: you are getting a list!
> echo -e "1\n2\n3" > foo
> cat foo
1
2
3
> set myFoo (cat foo)
> echo $myFoo
1 2 3
> echo $myFoo[0..2]
1 2
Therefore we apply the machinery available for lists; for instance, joining with a separator (note the extra backspace to get rid of undesirable spaces):
> echo {\b$myFoo}\n
1
2
3
# extra newline here
This is not ideal; string does it better:
> string join \n $myFoo
1
2
3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With