Skip to main content
Solved

How do I capture a variable but ignore standard error?


Forum|alt.badge.img+13

Hey all,

I'm working on a script to rename permissions on accounts moved from Open Directory to Active Directory.

As part of the checks (while loop logic) to see if the account exists I am querying AD for the GUID of the account:

/usr/bin/dscl /Active Directory/$domain/All Domains/ -read /Users/$user GeneratedUID | /usr/bin/awk '{print $NF;}')"

This works great for accounts that do exist in that domain, but if they don't the command fails. (I might have mistyped this from my script, but the logic works ;) )

How can I capture this information into a variable, and have sterr ignore the cases where the command populating the variable fails?

Best answer by eyemyth

Add ```
2> /dev/null
``` to redirect stderr to /dev/null

View original
Did this topic help you find an answer to your question?

2 replies

Forum|alt.badge.img+6
  • Contributor
  • 10 replies
  • Answer
  • October 11, 2012

Add ```
2> /dev/null
``` to redirect stderr to /dev/null


bentoms
Forum|alt.badge.img+35
  • Legendary Contributor
  • 4331 replies
  • October 11, 2012

Here's one i made earlier.

accountUniqueID=`dscl . -read /Users/$1 2>dev/null | ?grep UniqueID | cut -c 11-`

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings