Skip to main content
Question

Casper imaging scripts and command substitution

  • February 26, 2015
  • 4 replies
  • 18 views

Forum|alt.badge.img+4

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

Forum|alt.badge.img+4
  • Author
  • Contributor
  • February 26, 2015

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


davidacland
Forum|alt.badge.img+18
  • Valued Contributor
  • February 26, 2015

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?


Forum|alt.badge.img+13
  • Contributor
  • February 26, 2015

do you have any ~ in your script?


Forum|alt.badge.img+4
  • Author
  • Contributor
  • February 27, 2015

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?