Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fish shell - How to interpolate a subcommand?

In bash I can say:

$ echo "a$(echo b)c" abc 

How do I do this in the fish shell?

like image 443
Joshua Cheek Avatar asked Jun 15 '14 02:06

Joshua Cheek


People also ask

How do you set a variable in a fish shell?

Unlike other shells, fish has no dedicated VARIABLE=VALUE syntax for setting variables. Instead it has an ordinary command: set , which takes a variable name, and then its value.

How do I run a fish shell script?

To be able to run fish scripts from your terminal, you have to do two things. Add the following shebang line to the top of your script file: #!/usr/bin/env fish . Mark the file as executable using the following command: chmod +x <YOUR_FISH_SCRIPT_FILENAME> .

How do I change the prompt in fish?

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 ~/.


1 Answers

echo a(echo b)c 

If you have quotes, you must exit them:

echo "a"(echo b)"c" 

If your subcommand may have newlines, as of fish 2.3, you have to save and restore $IFS:

set -l IFS  echo "a"(cat ~/file.txt)"c" set -e IFS 

Eventually string will be able to handle this case.

like image 83
ridiculous_fish Avatar answered Sep 21 '22 16:09

ridiculous_fish