5

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

1 Answer 1

18

echo. Clearly less weird.

#!/bin/bash

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

diff <(echo "$a") <(echo "$b")
7
  • 2
    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 `('" Commented Jul 10, 2018 at 20:03
  • 5
    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. Commented Jul 10, 2018 at 22:02
  • I am getting the same error even though I'm using #!/bin/bash, is there something I am missing? Commented May 21, 2019 at 15:14
  • 2
    @Loupax Are you maybe running the script with sh scriptname? Commented May 21, 2019 at 19:21
  • @Kusalananda You got me, I'll look up what shell sh actually is Commented May 22, 2019 at 6:38

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.