Assignment Statement

An assignment statement assigns a value to a variable. An assignment can be used whenever an expression is expected, and multiple assignments can be done in a single statement.

In Privilege Management for Unix and Linux 3.2 and earlier, assignments are not expressions and cannot be cascaded.

Beginning with Privilege Management for Unix and Linux 3.5+, assignments are expressions and can be cascaded anywhere an expression occurs.

list[n] = expression;

An expression can be a constant, variable, or complex equation.

var1 = var2 = var3 ... = value;

var1, var2, and var3 are assigned values.

IntegerString = "1234";
StringList = {"User1", "User2", "User3"};
Counter = 1;
TotalUsers = 5;
CurrentUsers = 3;
InactiveUsers = TotalUsers - CurrentUsers;
userString = user;
runuser = "root";
list1 = {"a1", "a2", "a3"};
list2 = list1;
list2[0] = "l1"

The following occurs:

InactiveUsers is set to 2 (5 – 3)
userString = user; sets userString to the submitting user.
runuser = "root"; sets runuser to root.
list2[0] = "l1" causes list1 to still be {"a1", "a2", "a3"}, list2 has the value of
{"l1", "a2", "a3"}
a = b = c = d = 0;

The variables a, b, c, and d are cascaded and assigned the same value (0).