Skip to main content
Question

Null/Non-Null Script Parameterß

  • September 13, 2019
  • 1 reply
  • 0 views

Forum|alt.badge.img+6
  • Contributor
  • 24 replies

Hello JAMFers,

I'm writing a script to have a local variable, and an IF statement to say "If a 4th parameter/argument was passed to the script, use that instead."

For example:

if [[ ! -z "${4}" ]];then
  theVariable="${4}"
fi

However, I suspect that JAMF might be sending non-null characters for all empty script parameter fields (e.g. a period ".").

An example of what I mean is this:

/usr/local/bin/setup_script.sh "Mount_Point" "Computer_Name" "Username" . . . . . . . .
# 1st, 2nd, and 3rd fields being reserved for JAMF's internal fields.
# Each period represents subsequent parameters.

Each period can be passed to a script to serve as placeholders, and substituted with quoted text to pass parameters to a script in the intended parameter. So let's say that I have a generic setup script that want to pass certain values to some machines and not all.

/usr/local/bin/setup_script.sh "Mount_Point" "Computer_Name" "Username" "LocalAdmin" "AutoUpdates" . . . . . .
/usr/local/bin/setup_script.sh "Mount_Point" "Computer_Name" "Username" . "AutoUpdates" . . . . . .

Do you think my IF statement will be sufficient to check for non-null fields? Or would someone please help me verify how JAMF is verifying parameter positions?

Thank you!

1 reply

Forum|alt.badge.img+16
  • Valued Contributor
  • 1002 replies
  • September 13, 2019

Pretty sure I have used IF statements on JAMF parameters before without issue.
I tend to just use the fact that if you double square it will actually evaluate automatically to true if you directly query the variable.
I am not sure if this would behave much difierently than -z but you never know and it's what I have tended to do...
i.e.

if [[ "$1" ]]; then
echo "yes"
else
echo "no"
fi

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings