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.

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

Like
SOLVED Posted: by justin.smith

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

Like
SOLVED Posted: by justin.smith

or

bash /path/to/file

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

Like
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:

#!/bin/bash

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'
Like
SOLVED Posted: by gregory.floro

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

Like