Slashes in Scripts parameters

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


Honored Contributor

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


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

Contributor III

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)

Legendary Contributor II

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.


if [ ! -z "$4" ]; then

echo "$mystring"
$ sudo jamf runScript -script -path ~/Desktop/ -p1 "Hello/World"
$ Running script
$ 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.