I'm trying to tidy up my search domain script by only grabbing the available network interfaces. If I use my existing one from my first boot script I receive errors due the fact that not all of them are present. It doesn't effect the search domain being applied, but the end user sees the error through self service attempting to run it multiple times. Anyway here's what I have so far. I can't figure out how to escape the space in between say Display Ethernet or to keep Wi-Fi intact.
#!/bin/bash
declare -x SearchDomains="my.domain.com"
export devlist="$(networksetup -listnetworkserviceorder | grep Hardware |
sed -e 's/^(H.*rt: (.*), Device: (.*))/1/'
-e 's/[()*#]//g' -e 's/[ -]/_/g')"
echo My device list:
for dev in ${devlist}; do /usr/sbin/networksetup -setsearchdomains ${dev} ${SearchDomains}; done
echo
exit 0