bash - 在此处使用两个字符串

标签 bash shell heredoc

我可以使用 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/

相关文章:

android - 使用 Android 应用程序运行脚本

bash - 使用 sed 在捕获组内替换

bash - 如何写一个简单的分层Makefile?

linux - ./${SCRIPT##*/} 在 bash 脚本中意味着什么

cron - 用于记录 LSF (bsub) 作业完成情况的脚本

linux - 发送 ssh 命令时防止本地 shell 替换变量

bash - 如何捕获更改文件夹中文件的事件?

Python - 打开新的 shell 并运行命令

bash - 在heredoc中禁用命令替换?

python - PyCharm 自动完成,类型列表