INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

store result of command into an array

store result of command into an array

(OP)
Hey guys,

New on this forum. Would really appreciate some help on this issue I'm having. I'm trying to store
the result of this command into an array so that I can compare this array with another array so
I can get the difference between the two. My first problem is storing this output into an array? Any suggestions would be great guys.

launchctl list | egrep -v "com.apple|anonymous.launchd|anonymous|master|cron|ntpd|bombich|cupsd" | awk '{print $3}'

org.test.squid
org.test.disk
org.test.maint

RE: store result of command into an array

(OP)
[[ "${array1[@]}" = "${array2[@]}" ]] && echo same || echo different

RE: store result of command into an array


Perhaps just like this it would work:

CODE

array2=$(launchctl list | egrep -v "com.apple|anonymous|master|cron|ntpd|bombich|cupsd" | awk '{print $3}') 
3eyes

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

RE: store result of command into an array


PS: In order for the compare statement you posted to work, you would need both arrays to be SORTED.
Otherwise they will be different even if the contain the same elements:

CODE

==> a1=$(ls -1 *.log)
==> echo $a1
EXTERNAL_EXAMPLE_13762668.log EXTERNAL_EXAMPLE_25100426.log load_example.log student.log
==> a2=$(ls -1r *.log)
==> echo $a2
student.log load_example.log EXTERNAL_EXAMPLE_25100426.log EXTERNAL_EXAMPLE_13762668.log
==> [[ "${a1[@]}" = "${a2[@]}" ]] && echo "Equal" || echo "Different"
Different 
noevil

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close