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!
  • Students Click Here

*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.

Students Click Here


compare lists of comma separated options

compare lists of comma separated options

compare lists of comma separated options

I want to compare list of default shells with list of shells on a host (to get "missing" and superfluous shells configured on a host).
Below is my current solution in ksh script using arrays.
Do you see it could be done more efficient/easier with e.g. awk or the solution I paste is good enough?

CODE --> test

$ cat ./test_arr

set -A stdshells $(echo $S1|sed s/\,/\ /g)
set -A hstshells $(echo $S2|sed s/\,/\ /g)

checkshells ()
for a in "${stdshells[@]}"; do
  if [[ " ${hstshells[*]} " != *" $a "* ]]; then
    printf "$a(-),"

for a in "${hstshells[@]}"; do
  if [[ " ${stdshells[*]} " != *" $a "* ]]; then
    printf "$a(+),"

checkshells | awk '{sub(/,$/,"");print}'

$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly
$ ./test_arr
$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly,/bin/csh
$ ./test_arr
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly,/bin/csh,/bin/csh
$ ./test_arr
$ export S1=/bin/bsh,/bin/csh,/bin/false,/bin/ftponly,/bin/csh,/bin/csh2
$ ./test_arr
$ export S2=/bin/bsh,/bin/csh,/bin/extra,/bin/ftponly,/bin/csh,/bin/csh,EXTRA
$ ./test_arr

RE: compare lists of comma separated options

Seems good enough, I would probably have sorted the two lists and used 'diff' and customised output format, or 'comm' and my own format handling, but I don't think it would be any better really. And yes, you could use perl/awk/whatever but it would just be the same code as you wrote in a different language...

tgmlify - code syntax highlighting for your tek-tips posts

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!

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