Tag

bash

2 posts

Bash is a Unix shell and command language written by Brian Fox for the GNU Project as a free software replacement for the Bourne shell.

Code

The short-circuiting in bash

Bash script writing is a import approach to configure the linux system. Suppose we wish to add a user if not exists, the command may seems as follow:

Bash
TARGET_USER=alice
if (! id -u $TARGET_USER > /dev/null 2>&1 ); then
    echo "creating user $TARGET_USER"
    # adduser $TARGET_USER
fi

However, it is kind of too long. In this case short-circuiting is a alternative solution.