我可以使用 herestrings 将字符串传递给命令,例如
cat <<< "This is a string"
如何使用 herestrings 将 两个 字符串传递给命令?我怎样才能做类似的事情
### not working
diff <<< "string1" "string2"
### working but overkill
echo "string1" > file1
echo "string2" > file2
diff file1 file2
最佳答案
您不能使用两个 herestrings 作为同一命令的输入。实际上,最新的一个将取代所有其他的。示范:
cat <<< "string 1" <<< "string 2" <<< "string 3"
# only shows "string 3"
另一方面,如果你真的想要区分两个直接输入,你可以这样做:
diff <(echo "string 1") <(echo "string 2")
关于bash - 在此处使用两个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19904460/