Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Environment and Variables

clitest provides powerful features for managing environment variables and working directories.

Setting Variables

Using %SET

Capture command output into a variable:

$ printf "value\n"
%SET MY_VAR
*

Using set

Set environment variables directly:

set FOO bar;
set PATH "/usr/local/bin:$PATH";

Variable References

Basic Reference

Use $VAR to reference variables:

set FOO bar;
$ echo $FOO
! bar

Explicit Reference

Use ${VAR} when the variable name is followed by text:

set FOO bar;
$ echo ${FOO}123
! bar123

Working Directory Management

The working directory is managed through a special variable PWD. This can be set directory, or various commands can change it.

Changing Directory

Change the current working directory. The PWD is updated to the new directory for the duration of the test, unless another command changes it:

cd "subdir";

Using Temporary Directories

Create and use a temporary directory. The current working directory is automatically set to the temporary directory, and when the block ends, the temporary directory is automatically deleted.

using tempdir;

Creating New Directories

Create a new directory for testing. The current working directory is automatically set to the directory, and it is deleted when the block ends.

using new dir "subdir";

Using Existing Directories

Use an existing directory. The current working directory is automatically set to the directory, and it is not deleted when the block ends.

using tempdir;
$ mkdir -p subdir
using dir "subdir";

Special Variables

PWD

The PWD variable is special and controls the current working directory:

$ mktemp -d
%SET TEMP_DIR
*

# Set PWD to change working directory
$ echo $TEMP_DIR
%SET PWD
*

Environment Variable Examples

Combining Variables

set A 1;
set B 2;
set C "$A $B";
$ echo $C
! 1 2

Using Variables in Commands

set DIR "subdir";
using new dir "$DIR";
$ echo $PWD
! %{PATH}/subdir

Conditional Environment Setup

if $TARGET_OS == "linux" {
    set PATH "/usr/local/bin:$PATH";
}