Problem assigning parameter 10 & 11 in script

mm2270
Legendary Contributor III

I'm running into an odd issue I can't figure out with a script I'm working on. You know how you can assign parameters in a policy (or Casper Remote) to $4 through $11 to pass back to the script? Well, it seems anything past $9 does not get properly assigned, no matter what I do or try.
I started running into strange behavior with the script and set up a 'debug' version that echoed back the assignments. What I see is that $4 through $9 are perfectly assigned, and $10 $11 echo back as /0 /1. In other words, its ignoring the double digit and using the 0 and 1 last characters from the parameter. This fouls up the script since its assigning bad information into the variables for the script.

Does anyone know how to get around this? Is this just a bug in Casper or an issue with bash scripts in general? I've never seen this before because honestly I've never had a need to assign more than one or two parameters in a script, but in this case I want to use all of them, if possible.

Any insights would be welcome.

1 ACCEPTED SOLUTION

nessts
Valued Contributor II

assuming your script is a bash script? try wrapping the variable in {}
so echo ${10} instead of $10
using an editor that does syntax highlighting would probably help too
(BMStudio-A211636) /tmp 124 8:13am% asd.sh a b c d e f g h i j k l
a
b
c
d
e
f
g
h
i
a0
a1
a2
now wrapped in {}
j
k
l
(BMStudio-A211636) /tmp 125 8:13am% cat asd.sh #!/bin/bash

echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
echo $8
echo $9
echo $10
echo $11
echo $12
echo "now wrapped in {}"
echo ${10}
echo ${11}
echo ${12}
(BMStudio-A211636) /tmp 126 8:13am%

View solution in original post

7 REPLIES 7

rockpapergoat
Contributor III

sounds like jamf needs to fix that.

some examples:

http://wiki.bash-hackers.org/scripting/posparams

assign past 9 with ${10}, etc.

nessts
Valued Contributor II

assuming your script is a bash script? try wrapping the variable in {}
so echo ${10} instead of $10
using an editor that does syntax highlighting would probably help too
(BMStudio-A211636) /tmp 124 8:13am% asd.sh a b c d e f g h i j k l
a
b
c
d
e
f
g
h
i
a0
a1
a2
now wrapped in {}
j
k
l
(BMStudio-A211636) /tmp 125 8:13am% cat asd.sh #!/bin/bash

echo $1
echo $2
echo $3
echo $4
echo $5
echo $6
echo $7
echo $8
echo $9
echo $10
echo $11
echo $12
echo "now wrapped in {}"
echo ${10}
echo ${11}
echo ${12}
(BMStudio-A211636) /tmp 126 8:13am%

rockpapergoat
Contributor III

corollary: can you find some other way to pass parameters to the script? seems like passing 11 args to the thing may be on the verge of "yur doin' it wrong."

mm2270
Legendary Contributor III

@Nate - Well, I can certainly hardcode some of the parameters in and I'm thinking about that, but in this case for what I'm trying to do in making this flexible from a policy, it would be helpful to be able to assign them all in the policy itself. If worse comes to worse, I can just forget a few. I'm just not sure why it would be having an issue since this seems to be something the Casper Suite was designed to do.

@Todd, I'll give your suggestion of wrapping it in the curly brackets a go and see what happens. FWIW, I use TextWrangler when I write my scripts. I'm pretty certain this isn't a general syntax issue since i can run the script locally and it works fine. Its when it gets passed down by Casper that the assignments for $10 & $11 don't work.

Thanks

rockpapergoat
Contributor III

what are the parameters you need to pass? maybe i can help you work out a different method of passing the same data.

nessts
Valued Contributor II

maybe Casper has a bug and needs to wrap them in their underlying structure then.

mm2270
Legendary Contributor III

@Todd, that did it. Placing those 2 assignments in {} fixed it. Thanks for the help!