Slashes in Scripts parameters

ngidzak
New Contributor

I am trying to pass a string with the character '/' in it

JSS seems to be removing that and everything after it when saving the parameter.
Is there an escape key I need to include

4 REPLIES 4

bpavlov
Honored Contributor

Have you tried including a back slash before the forward slash / like this / ?

wdpickle
Contributor

have you tried '/'? that is a in front of the /

McAwesome
Valued Contributor

To explain the suggestion, the backslash character escapes the next character. So say you want to do something with a file in /Library/Application Support. If you try doing

cp /Library/Application Support/file.example .

It will error out because no folder named Application exists in Library. To get around that, you add the "" in. So

cp /Library/Application Support/file.example .

will copy file.example to the current location. So for your needs, since you don't want the / to be treated as a file path, you'll need to add the backslash in front of it to escape the normal rules.

(You know what an escape key is, so this is less for you specifically and more for anyone down the line who stumbles here)

mm2270
Legendary Contributor III

I assume from how you worded your posting that you're talking about a script parameter, like $4 or whatever. If so, try wrapping the parameter or variable assigned to that parameter in the script in double quotes wherever you're using it in the script. For example.

#!/bin/sh

if [ ! -z "$4" ]; then
    mystring="$4"
else
    exit
fi

echo "$mystring"
$ sudo jamf runScript -script test.sh -path ~/Desktop/ -p1 "Hello/World"
$ Running script test.sh...
$ Script exit code: 0
$ Script result: Hello/World

I'm pretty sure that should conserve the slashes in the string since the quotes should stop it from being seen as path delimiters, and just instead as a string as you intended. My guess is its getting stripped off because the variable isn't quoted in your script, but hard to know since you didn't post the script itself.