Pregunta

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
¿Fue útil?

Solución

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")

Otros consejos

You can simply concatenate the two strings:

cat <<< "string1""string2"

(not the lack of space between the two). The here string now consists of a single word whose contents are the contents of the two strings.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top