Passing a space "\ " in a variable for a sh

bentoms
Release Candidate Programs Tester

Hi all,

Yep it's time for my daily question.

This one should be easy!!

We rename all our startup disks X. So I've written a little script to do this.

It's basically;

sudo -u $AdminUser -p $AdminPassword diskutil rename $CurrentVolumeName $NewVolumeName

The above variables are all passed to $4-8 in Casper fine.

I can use the above to change X to Data or any other one word name.

Trouble is I want to rename 'Macintosh HD.' via ard or locally I'd write 'Macintosh HD' as 'Macintosh HD"

However Casper seems to pass te variable with the so the mac see's it as an illegal character.

Missing out the leads to the mac think ing I'm passing 3 variables & that too fails.

What's the simple thing I'm missing this time??

Regards,

Ben. Grey Communications Group Limited
Registered No. 1795794, Registered in England
Registered Office The Johnson Building, 77 Hatton Garden, London, EC1N 8JS
VAT Number GB 404 6245 78

10 REPLIES 10

talkingmoose
Moderator
Moderator

You would add the quotes or escapes when putting this into a script, but
On 3/17/10 5:20 PM, "Ben.Toms at grey.com" <Ben.Toms at grey.com> wrote:
you're entering this into one of Casper Remote's (I assume) script parameter
fields. Correct?

While I haven't tested this, have you just tried:

Macintosh HD

with no quotes and no escapes?

--

William Smith
Technical Analyst
Merrill Communications LLC
(651) 632-1492

bentoms
Release Candidate Programs Tester

Yep I'm entering this as a parameter.

Leaving out the , seems to pass it two words. (Macintosh, HD).

I'll retest using " & ' but pretty sure it tries to pass using the quotes.

Seems like it's being passed as is, so all characters...

Regards,

Ben.

tlarkin
Honored Contributor

I wonder if you can declare an internal field separator, ie IFS in the script to tell it how to treat white space. It seems it wants to treat spaces with commas, to delimit the values. I am guessing it was done this way for injection into the database????? Therefore, it delimits each filed by a comma?

abenedict
New Contributor II

I had a similar issue recently and what I ended up putting in my script to
make it work was double quotes so it looked like below.

CurrentVolumeName=""$5""

This way you can put in the volume name with out the and it will quote it
correctly.

Hope this helps.
:)

Alan

--
Alan Benedict
?
Macintosh Technician
The Integer Group
O: 515-247-2738
C: 515-770-8234
http://www.integer.com

tlarkin
Honored Contributor

This will get you the current boot volume, with spaces and no slashies

/usr/sbin/diskutil info `/usr/sbin/bless --getBoot` | /usr/bin/sed '/^
*Volume Name: */!d;s###'

Br3ck
New Contributor III

Sorry to resurrect this ancient thread but @bentoms where did you land on this? I just hit this today and can't seem to get JAMF to respect a space in $4 :(

bentoms
Release Candidate Programs Tester

@br3k whoa.. this post is from 2010!

but try: "${4}"

Br3ck
New Contributor III

@bentoms - This shows my desperation! Thank you for the prompt response, will have a go.

Br3ck
New Contributor III

So JAMF clearly passes the parameter through just fine??

Something else is borked cause I ran this with Excel open :(

#!/bin/bash

process="$4"
url="$5"

echo $process "is what JAMF sees"

if pgrep -xq $process  

then

    echo $process "is running. Exiting"

else

    ## DOWNLOAD UPDATE PKG ##

    echo "Downloading Office 365 media from https://www.microsoft.com"

#   mkdir /tmp/O365

#   cd /tmp/O365

    ## DOWNLOADING PKG##

#   curl -O -J -L $url

    ## CAPTURING O365 PKG NAME AS VARIABLE ##

#   package=`ls /tmp/O365`

#   echo "Installing $package..."

#   sudo installer -pkg "/tmp/O365/$package" -target /

#   echo "Install Complete"

    ## CLEANUP ##

#   echo "Cleaning Up Before Exiting"

#   rm -rf /tmp/O365/

#   echo "Cleanup Complete, Now Exiting."

#   echo "$4 Updated Successfully"

fi

exit 0

In the log of the policy when ran:

01472632376847e5987df8d83e7be384

bentoms
Release Candidate Programs Tester

@Br3ck i'd start a new thread here or ask in the #bash channel on the macadmins slack.