I have $a and $b. I want to run diff on those.

The best I have come up with is:

diff <(cat <<<"$a") <(cat <<<"$b")

But I have the district feeling that I am missing a clever Bash syntax to do that (as in "Why don't you just use foo?").


echo. Clearly less weird.


a="`seq 10`"
b="`seq 0 11`"

diff <(echo "$a") <(echo "$b")
  • 1
    How do you use this in a bash script? Trying to output a diff of two strings using this syntax and I get "syntax error near unexpected token `('"
    – Andrew
    Jul 10 '18 at 20:03
  • 4
    I figured out why I couldn't get it to work. Process substitution is a bash feature, which is usually not available in /bin/sh. My bash script had the wrong shebang. Was #!/bin/sh but should have been #!/bin/bash.
    – Andrew
    Jul 10 '18 at 22:02
  • I am getting the same error even though I'm using #!/bin/bash, is there something I am missing?
    – Loupax
    May 21 '19 at 15:14
  • 2
    @Loupax Are you maybe running the script with sh scriptname?
    – Kusalananda
    May 21 '19 at 19:21
  • @Kusalananda You got me, I'll look up what shell sh actually is
    – Loupax
    May 22 '19 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.