Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8873619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:30:39+00:00 2026-06-14T18:30:39+00:00

I have a variable $data and variable $file in a bash script: data=$(echo $(printf

  • 0

I have a variable $data and variable $file in a bash script:

data=$(echo "$(printf '%s\n' "${array[@]/%/$'\n\n'}")")
file=$(<scriptfile_results)

Those variables will contain text. How to compare those two? One option is to use diff(1) utility like this:

diff -u <(echo "$data") <(echo "$file")

Is this an correct and elegant way to compare content of two variables? In addition how is the <( ) technique called? As I understand, for each <( ) a temporary file(named pipe) is created..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:30:40+00:00Added an answer on June 14, 2026 at 6:30 pm

    Yes, diff <(echo "$foo") <(echo "$bar") is fine.

    By searching the bash manpage for the characters <(, you can find that this is called “process substitution.”

    You don’t need to worry about the efficiency of creating a temporary file, because the temporary file is really just a pipe, not a file on disk. Try this:

    $ echo <(echo foo)
    /dev/fd/63
    

    This shows that the temporary file is really just the pipe “file descriptor 63.” Although it appears on the virtual /dev filesystem, the disk is never touched.

    The actual efficiency issue that you might need to worry about here is the ‘process’ part of “process substitution.” Bash forks another process to perform the echo foo. On some platforms, like Cygwin, this can be very slow if performed frequently. However, on most modern platforms, forking is pretty fast. I just tried doing 1000 process substitutions at once by running the script:

    echo <(echo foo) <(echo foo) ... 997 repetitions ... <(echo foo)
    

    It took 0.225s on my older Mac laptop, and 2.3 seconds in a Ubuntu virtual machine running on the same laptop. Dividing by the 1000 invocations, this shows that process substitutions takes less than 3 milliseconds—something totally dwarfed by the runtime of diff, and probably not anything you need to worry about!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a bash script that will take a text file
I have a variable that contains an array from form data, seen below: $option1
I have a bash script that uploads a file via SFTP, with a command
I have .sh file with the next content: #!/bin/bash echo -------- uploader.sh v 0.1
SOLVED! I`m trying save data from array in variable. I have in controller: $data
I need to read some configuration data into environment variables in a bash script.
Let’s say I have the following Bash script: while read SCRIPT_SOURCE_LINE; do echo $SCRIPT_SOURCE_LINE
I have a script that reads in a large data file 3GB I don't
I have variable which I populate from JSON formated data. Something like: var time=my_data[data.results[i].id].time;
I have a variable () loaded with a html code: $.get(url, function (res, data)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.