do
Execute commands within loop constructs
TLDR
View documentation for the for keyword
View documentation for the while keyword
View documentation for the select keyword
View documentation for the until keyword
SYNOPSIS
do [-u user] [-g group] command [arguments]
PARAMETERS
-u user
Specify the user ID or user name to execute the command as. If a user name is provided, do resolves the user ID from the /etc/passwd file.
-g group
Specify the group ID or group name to execute the command as. If a group name is provided, do resolves the group ID from the /etc/group file.
command
The command to be executed.
[arguments]
Any arguments to be passed to the command.
DESCRIPTION
The do command is a utility primarily used within the Slackware Linux distribution's build scripts. It's designed to execute other commands with a modified user ID and/or group ID. This is particularly useful during package building and installation processes where certain operations need to be performed as a specific user (often a non-root user) to prevent unintended modifications to system files or to ensure proper permissions on newly created files. The do command helps enforce a least-privilege approach, minimizing the risk of running build processes entirely as root.
While the do command provides a controlled environment for executing commands, it is not a standard GNU/Linux utility and is specific to Slackware's build infrastructure. The user and group IDs can be specified numerically or by name. It's crucial to use do correctly to avoid permission issues or security vulnerabilities within the build process.
It simplifies setting the user and group IDs temporarily, before executing the provided command and then reverting to the original IDs after the command is finished.
CAVEATS
The do command is highly specific to Slackware Linux and may not be available on other distributions. Using incorrect user/group IDs can lead to permission errors. It's essential to understand the required permissions for the command being executed. It typically must be run as root.
EXAMPLE USAGE
To run the command 'make install' as user 'nobody':
do -u nobody make install
To run the command 'chown -R' as group 'staff' with the user 'bob':
do -u bob -g staff chown -R /path/to/files
HISTORY
The do command was specifically written to facilitate the Slackware Linux build system, giving build scripts a standardized way to temporarily change user and group IDs before and after the execution of certain binaries.