Skip to main content
Jamf Nation, hosted by Jamf, is the largest Apple IT management community in the world. Dialog with your fellow IT professionals, gain insight about Apple device deployments, share best practices and bounce ideas off each other. Join the conversation.

Scripting help (or am I going mad..)

I'm working upon a larger script to do some finder customisation and having a problem with a dscl lookup which is quite confusing unless I'm missing something silly!

All I'm wanting this small bit to do it echo out the path to the logged in active directory users network home directory, SMBHome.

Here's the really basic script

#!/bin/bash CurrentUser=$(stat -f%Su /dev/console | awk '!/root/') ADHome=$(dscl . -read /Users/"$CurrentUser" SMBHome) echo "$ADHome"

If I run that in terminal the result it outputs is different to what happens running the exact same commands manually. See the screen shot where I've run the script and then copied the contents directly into terminal and it gives a different answer.

As you can see in the script result it misses the first \ and then \a from the path, I assuming I'm missing something but not sure what. Any one any ideas?

Like Comment
Order by:
SOLVED Posted: by CypherCookie

That works just fine for me for both ways of executing it. I'm invoking the script via the same method as you as well.

SOLVED Posted: by achmelvic

Thanks @CypherCookie

So I'm not necessary going mad, there is something weird going on, I'll give it a try on another mac later on.

SOLVED Posted: by jssmith

When executing the script, try doing it without "sh" Just use the path to the file.

SOLVED Posted: by jssmith


bash /path/to/file

SOLVED Posted: by millersc

Doing it with the "sh" is removing the slash. Doing with just the path, gives the correct response. JAMF would run it without the "sh" since it's running as root.

SOLVED Posted: by merps

I've been messing with this for a while and I think your variable is fine, and it's just the combination of echo and bash that is chopping up your output.

If you want to check on the results, try something like this:


CurrentUser=$(stat -f%Su /dev/console | awk '!/root/')
echo $CurrentUser
ADHome=$(dscl . -read /Users/"$CurrentUser" SMBHome)
justHome=$(dscl . -read /Users/"$CurrentUser" SMBHome | awk '{print $2}')
echo "ADHome Returns:"
echo ${ADHome}
echo "$ADHome"
echo $ADHome
printf '%s' $ADHome
printf '\n'
echo "justHome Returns:"
echo ${justHome}
echo "$justHome"
echo $justHome
printf '%s' $justHome
printf '\n'
SOLVED Posted: by gregory.floro

Have you tried updating your script to include the "/" between "$CurrentUser"/SMBHome?
ADHome=$(dscl . -read /Users/"$CurrentUser"/SMBHome)

SOLVED Posted: by achmelvic

After a few weeks off just got back to looking at this, thanks for all the suggestions guys!

Thanks to @merps great test script it does look to work with the printf command rather than echo. The command which produces the right format is the one at the bottom:

printf '%s' $justHome
printf '\n'

Now to combine it with the larger script for adding a users network home to their Finder sidebar.

Thanks again for all the help.