Null/Non-Null Script Parameterß

zanb
New Contributor III

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 1

Look
Valued Contributor III

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