pfn*_*sel 4 bash shell heredoc
我可以使用herestrings将字符串传递给命令,例如
cat <<< "This is a string"
Run Code Online (Sandbox Code Playgroud)
如何使用herestrings将两个字符串传递给命令?我该怎么办呢
### not working
diff <<< "string1" "string2"
### working but overkill
echo "string1" > file1
echo "string2" > file2
diff file1 file2
Run Code Online (Sandbox Code Playgroud)
您不能使用两个herestrings作为同一命令的输入.实际上,最新版本将取代所有其他版本.示范:
cat <<< "string 1" <<< "string 2" <<< "string 3"
# only shows "string 3"
Run Code Online (Sandbox Code Playgroud)
另一方面,如果您想要的是两个直接输入,您可以这样做:
diff <(echo "string 1") <(echo "string 2")
Run Code Online (Sandbox Code Playgroud)