Documentation

Other programming considerations

This section describes other programming considerations. These consist of:

  • Boolean true and false variables
  • Format commands
  • Regular expression patterns
  • Wildcard search characters
  • Special characters

Boolean true and false variables

Many program statements rely upon conditional tests to determine the next program statement to execute. The if program statement is an example.

Conditional tests generally evaluate to either a true or false value. Although any positive, non-zero integer can represent a true value, the integer 1 is normally used. The integer 0 represents a false value.

The following are some Boolean true and false variable examples:

Example

LoopControl = false; #sets LoopControl to 0

Example

LoopControl = true; #sets LoopControl to 1

Format commands

Format commands insert values into character strings known as variable substitution. These commands specify where to insert the character string and how to format it. Format commands begin with a percent (%) sign followed by a format code. There are two categories of format commands: Character format and Time format.

Character format commands

The sprintf() function AND fprintf and printf procedures use character format commands. The following table describes the commands.

CharacterFormat Command
%dDecimal value
%iInteger value
%oOctal value
%sString of characters
%uUnsigned decimal value
%xCharacter hexadecimal value without a leading zero and with letters in lowercase (that is, 0x87a4)
%XCharacter hexadecimal value without a leading zero and with letters in uppercase (that is, 0X87A4)
%%Percent sign

Example

This demonstrates how character format commands work. Given the following character string,

I have x dogs, y cats, and z fish

The character format commands can be used to insert actual numeric values for x, y and z. This is done as follows:

printf ("I have %d dogs, %d cats, and %d fish", DogCount, CatCount,\FishCount);

DogCount, CatCount and FishCount are variables containing numeric values.

The interpreter sequentially replaces each format command with one of the provided variables.

The replacement is done in sequential order. The first format command gets the first variable, and the second format command gets the second variable, etc.

Format commands can also use field modifiers to specify field width and whether to left justify a field.

Minimum field-width modifier

An integer placed between the percent sign and the command character determines the minimum width of a field. By default, the pad character is a blank. To pad with zeros instead of spaces, place a zero before the minimum field-width specifier.

For example, %04d pads an integer value with zeros if the integer value is less than four digits in length.

Maximum field-width modifier

A decimal point, followed by a maximum field width determines the maximum width of a field. If the value is longer than the specified maximum length, the value truncates on the right.

For example, %2.4d generates a field with a minimum length of two digits and a maximum length of four characters.

Left-justification field modifier

By default, all output is right-justified. To left-justify a field, place a minus sign directly after the percent sign.

For example, %-2.4d generates a left-justified field with a minimum length of two digits and a maximum length of four digits.

Time format commands

The strftime() function uses time format commands. The following table describes the commands.

ℹ️

Note

Time format commands can vary based on the operating system. We recommend that you consult the strftime manual pages for your local pbmasterd system.

CharacterCommand
%aThe abbreviated weekday name according to the current locale.
%AThe full weekday name according to the current locale.
%bThe abbreviated month name according to the current locale.
%BThe full month name according to the current locale.
%cThe preferred date and time representation for the current locale.
%CThe century number (year/100) as a two-digit integer.
%dThe day of the month as a decimal number (range 01 - 31).
%DEquivalent to %m/%d/%y.
%eLike %d, the day of the month as a decimal number, but space replaces a leading zero.
%EModifier. Use alternative format.
%gLike %G but without the century, (that is, with a 2-digit year, 00-99).
%GThe ISO 8601 year with century as a decimal number. The four-digit year that corresponds to the ISO week number (see %V). This has the same format as %y except that if the ISO week number belongs to the previous or next year, that year is used instead.
%hEquivalent to %b.
%HThe hour as a decimal number using a 24-hour clock (00-23).
%IThe hour as a decimal number using a 12-hour clock (01-12).
%jThe day of the year as a decimal number (001-366).
%kThe hour (24-hour clock) as a decimal number (0-23). A blank precedes single digits. See also %H.
%lThe hour (12-hour clock) as a decimal number (1-12). A blank precedes single digits. See also %I.
%mThe month as a decimal number (01-12).
%MThe minute as a decimal number (00-59).
%nA new line character.
%OModifier. Use alternative format.
%pEither AM or PM according to the given time value or the corresponding strings for the current locale. Noon is PM and midnight is AM.
%PLike %p but in lowercase: am or pm or a corresponding string for the current locale.
%rThe time in AM or PM notation.
%RThe time in 24-hour notation (%H:%M). For a version that includes seconds, see %T.
%sThe number of seconds since the Epoch.
%SThe second as a decimal number (00-61).
%tA tab character.
%TThe time in 24-hour notation (%H:%M:%S).
%uThe day of the week as a decimal (1-7) with Monday being 1.
%UThe week number of the current year as a decimal number (00-53) starting with the first Sunday as the first day of week 01.
%VThe ISO 8601:1998 week number of the current year as a decimal number (01-53) where week 1 is the first week that has at least four days in the current year and Monday as the first day of the week.
%wThe day of the week as a decimal (0-6) with Sunday being 0.
%WThe week number of the current year as a decimal number (00-53) starting with the first Monday as the first day of week 01.
%xThe preferred date representation for the current locale without the time.
%XThe preferred time representation for the current locale without the date.
%yThe year as a decimal number without a century (00-99).
%YThe year as a decimal number including the century.
%zThe time zone as hour offset from GMT.
%ZThe time zone name or abbreviation.
%+The date and time in date(1) format.
%%A % character.

The time format commands work in the same manner as character format commands.

Regular expression patterns

The Endpoint Privilege Management for Unix and Linux Security Policy Scripting Language supports extended regular pattern matching. Use these for pattern searches as well as forbidden and warning keystroke patterns.

ℹ️

Note

For more information on regular expressions, see the following:

grep

egrep

PatternExampleDescription
  Matches any character.
 abc.dMatch the string abc followed by any single character then a d.
[ ] Defines the beginning and end of a character class.
 [jJ]*Match an uppercase or lowercase j followed by any number of characters.
 [a-z]Match any lowercase characters a through z.
^ Not character (when used inside square brackets).
 [^a-z]Match any character except lowercase characters a through z.
- Match zero or more occurrences of the last pattern.
 abc*Matches the string ab followed by zero or more c’s.
? Match zero or one occurrences of the last pattern.
 abc?Match either ab or abc.
- Match one or more occurrences of the last pattern.
 abc+Match the string ab followed by one or more c’s.
{m} Match exactly m occurrences of the last pattern.
 abc{3}Match the string abccc.
{m,} Match m or more occurrences of the last pattern.
 abc{3,}Match abccc, abcccc, etc.
{m,n} Match at least m, but no more than n, occurrences of the last pattern.
 abc{3,5}Match abccc, abcccc, or abccccc.
( ) Group several characters or patterns together and treat as a single group.
 a(bc)+Match abc, abcbc, abcbcbc, and so forth.
| Match either of two patterns.
 ab|cMatch either ab or ac.
^ Match beginning of line (when outside square brackets).
 ^abcMatch abc only if it appears at the beginning of a line.
$ Match end of line.
 abc$Match abc only if it appears at the end of a line.
[:alnum:] Matches alphanumeric characters.
[:alpha:] Matches alpha characters.
[:blank:] Matches spaces or tabs.
[:boundary:] Matches a word’s boundaries.
[:cntrl:] Matches control characters.
[:digit:] Matches decimal digits.
[:graph:] Matches graphical characters.
[:lower:] Matches lowercase characters.
[:print:] Matches printable characters.
[:punct:] Matches punctuation marks.
[:space:] Matches any white space.
[:upper:] Matches uppercase characters.
[:xdigit:] Matches hexadecimal digits.

Wildcard search characters

The Endpoint Privilege Management for Unix and Linux Security Policy Scripting Language supports the standard set of shell-style, wildcard search characters. These are used for searches by the in operator and for forbidden and warning keystroke patterns.

CharacterExampleDescription
- Matches any number of characters. Case is not considered.
 j*Match j followed by any number of characters.
 j*eMatch a string starting with j and ending with e, with any number of characters between j and e.
? Matches any single character. Case is not considered.
 j?Match j followed by any single character.
 j?eMatch a string starting with j and ending with e, with any single character between j and e.
[ ] Match characters. Case is considered.
 [jJ]*Match upper or lowercase j followed by any number of characters.
 [a-z]Match any lowercase characters a through z.
  Not character.
 [^a-z]Match any character except lowercase characters a through z.

Special characters

The Security Policy Scripting Language supports a standard set of special characters. Use special characters in place of characters that are impossible to enter using the keyboard or have other meanings in policy language strings. These characters can be used in the same way as any other single character, and they should be enclosed in either single or double quotation marks.

CharacterCommand
\aAlert
\bBackspace
\nNewline
\rCarriage return
\tTab character
'Single quotation mark
"Double quotation mark
\Backslash

Example

Tab = '\t';

This sets the variable with the Tab character.

Example

StringExample = "start a new line \n";

This adds a new line character at the end of the string.


©2003-2025 BeyondTrust Corporation. All Rights Reserved. Other trademarks identified on this page are owned by their respective owners. BeyondTrust is not a chartered bank or trust company, or depository institution. It is not authorized to accept deposits or trust accounts and is not licensed or regulated by any state or federal banking authority.