Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using two here strings

I can use herestrings to pass a string to a command, e.g.

cat <<< "This is a string"

How can I use herestrings to pass two strings to a command? How can I do something like

### not working
diff <<< "string1" "string2"

### working but overkill
echo "string1" > file1
echo "string2" > file2
diff file1 file2
like image 429
pfnuesel Avatar asked Dec 20 '22 21:12

pfnuesel


1 Answers

You can't use two herestrings as input to the same command. In effect, the latest one will replace all others. Demonstration:

cat <<< "string 1" <<< "string 2" <<< "string 3"
# only shows "string 3"

On the other hand, if what you want is really diff two immediate inputs, you can do it this way:

diff <(echo "string 1") <(echo "string 2")
like image 95
JB. Avatar answered Jan 12 '23 10:01

JB.