Casper imaging scripts and command substitution

icejoran
New Contributor

Dear JAMF members,

In some of my casper scripts, which are initiated at boot time i use command substitution.
Somehow they are not interpreted and turned into empty strings.

A small example;

cat << my_awesome_script > /tmp/the_script.sh
#!/bin/bash

jenkins_version=$(ls -tr1 /usr/local/Cellar/jenkins/ | tail -n1)
jenkins_version_different=ls -tr1 /usr/local/Cellar/jenkins/ | tail -n1
my_awesome_script

the contents of my script looks like this after imaging (the scripts are executed after the imaging process),
jenkins_version=
jenkins_version_different=

So somehow casper must parse the scripts and removes certain characters or complete strings.
Does anyone have the same experience? It would help me big time if someone could shine a light on this.

Many thanks!

4 REPLIES 4

icejoran
New Contributor

please let me know if i don't provide enough info, or if my way of asking has rough edges :)

davidacland
Honored Contributor II

I've just tried your code above on our test JSS and it worked ok. I changed the jenkins_version folder to be a different location as I don't have a /usr/local/Cellar/jenkins/ on my Mac but other than that it worked ok. I tested on JSS version 9.63, what are you using?

jesseshipley
Contributor

do you have any ~ in your script?

icejoran
New Contributor

Currently i'm on 9.64 (will be upgraded to 65 soon).
I make use of tildes which do work fine actually.

In the meantime i did more testing and it seems to work if i escape the dollar signs like this,
bla=$(exec something)
also an exit status variable needs to be escaped; $?
the same counts for backticks, this example works; `ls -1 /tmp | tail -n1`

@davidacland: interesting that it works for you, just like i try to use it.
could it be a problem related to the type of characters? UTF-8 vs something else?