0

so I'm trying to compare user lists in bash, file vault enabled users vs users I've defined. As a test I ran:

for i in "$ulist"; do
  if ($i == *testuser*) || ($i == *otheruser*)
  then
    echo "dont' change $i"
  else
    echo "change $i"
  fi
done

but it only returns

testuser
otheruser
x
y
change z

for the record:

ulist=$(fdesetup list | cut -d',' -f1)

any idea why it just cycles through the whole list without really comparing it the way I want it to? In the end I want to be able to skip modifying the users that I've told it skip.

3
  • 2
    The code you post contains syntax errors and could not possibly return the output you report. For a start, see shellcheck.net and fix the errors it points out. Commented Mar 12, 2016 at 18:32
  • Quoting the for argument produces exactly one iteration. Commented Mar 12, 2016 at 18:34
  • Yeah, I'm very new to bash, but I found that it's very hard to compare an array against another array and produce what I want. I ended up just finding a way to only get the result I wanted without having to check through two arrays. I'm still having tons of other small issues but so far this hurdle has been crossed. Commented Mar 16, 2016 at 1:36

2 Answers 2

1

I guess what you actually want is something like

fdesetup list |
grep -vE '^(test|other)user,'

If you really want the verbose do/don't output, change the grep to a simple sed script which does that.

Sign up to request clarification or add additional context in comments.

Comments

0

Yeah, I'm very new to bash, but I found that it's very hard to compare an array against another array and produce what I want. I ended up just finding a way to only get the result I wanted without having to check through two arrays. I'm still having tons of other small issues but so far this hurdle has been crossed. I did end up using grep to find the user and awk to print just the first column I wanted. This was my first Stack post, thanks for the help all.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.