Reputation: 1744
In Bash/Zsh, it is Okay using cat for a multiline message, eg:
cat <<DELIM
This is line 1
This is line 2
DELIM
However, the above code does not work for Fish Shell. Is there a way of doing so?
Upvotes: 9
Views: 3574
Reputation: 15934
Fish doesn't have "Here documents".
The easiest way to do this is probably to use printf
, e.g.:
printf "%s\n" "This is line 1" "This is line 2"
Or you can take advantage of the fact that fish scans for matching quotes across multiple lines:
echo "This is line 1
This is line 2"
If you wish to have the ending quote on the next line to ease inserting more lines, you can use echo -n
:
echo -n "This is line 1
This is line 2
"
Upvotes: 12
Reputation: 5148
This is what I ended up using for my block of text. Read the tip about printf from faho. But wanted the code to be looking like the block itself.
printf "\t%s\n" \
"###################" \
"# #" \
"# Multiline block #" \
"# #" \
"###################"
%s: Is the strings encapsulated in double quotes.
\n: New line.
\t: Horizontal tab.
Mixing it together inserts a tab before each line, indenting the text. And it adds a carriage return at the end of each line.
Upvotes: 8