Search code examples
fish

How to set an environment variable to file contents in fish


My config.fish file for fish shell has something like the following:

set -x MY_VARIABLE "Hello World!"

How could I get the results from reading the first line of a text file:

set -x MY_VARIABLE read_file('hello.txt')

Is there some way to do this in Fish? I cant use cat and a subshell like I would in bash.


Solution

  • Use a subcommand: set -x MY_VARIABLE (head -1 hello.txt). Or use the read command: read -x MY_VARIABLE < hello.txt.