The venv CLI tool is a versatile utility for managing environment variables in a bash environment. It allows users to install, set, get, delete, and list environment variables across various types, including regular variables, arrays, and associative arrays. This tool is particularly useful for managing environment configurations for scripts and applications.
Before using the venv tool, it must be installed in the desired directory. This sets up the necessary configuration files for managing environment variables.
The install command initializes the environment system in the specified directory.
venv install /path/to/install
This command creates a directory structure with a config.sh file and separate files for storing regular variables, arrays, and associative arrays.
The install command sets up the environment in the specified directory, preparing it for storing and managing environment variables.
venv install /path/to/installThe set command allows you to define environment variables. This command supports setting regular variables, arrays, and associative arrays.
venv set status "active" --config /path/to/config.shvenv set favorite_colors "Cyan/Blue" "Green/Magenta" "Red/Orange" "Yellow/Ocre" --config /path/to/config.shvenv set mode_descriptions "Battery saver":"Reduces performance to save battery" "High performance":"Maximizes performance at the cost of battery life" --config /path/to/config.shThe get command retrieves the value of a specified environment variable. It can fetch regular variables, arrays, and associative arrays.
status=$(venv get status --config /path/to/config.sh)
echo "Status: $status"
output=$(venv get favorite_colors --config /path/to/config.sh)
eval "arr=($output)"
echo "First color: ${arr[0]}"
echo "Second color: ${arr[1]}"
echo "Third color: ${arr[2]}"
echo "Fourth color: ${arr[3]}"output=$(venv get mode_descriptions --config /path/to/config.sh)
declare -A descriptions
while IFS=':' read -r key value; do
descriptions[$key]=$value
done <<< "$output"
echo "Battery Saver Mode Description: ${descriptions["Battery saver"]}"
echo "High Performance Mode Description: ${descriptions["High performance"]}"The delete command removes a specified environment variable from the configuration.
venv delete status --config /path/to/config.shThe list command displays all the variables that are currently set in the configuration, including their types.
venv list --config /path/to/config.sh
The uninstall command removes the environment system from the specified directory. This will delete all environment variables and their configuration files.
venv uninstall /path/to/install
venv install /home/user/env
-
Regular Variable:
venv set username "john_doe" --config /home/user/env/config.sh -
Array Variable:
venv set languages "Python" "JavaScript" "Bash" --config /home/user/env/config.sh -
Associative Array Variable:
venv set user_info "name:John Doe" "email:[email protected]" --config /home/user/env/config.sh
-
Regular Variable:
username=$(venv get username --config /home/user/env/config.sh) echo "Username: $username" -
Array Variable:
output=$(venv get languages --config /home/user/env/config.sh) eval "arr=($output)" echo "First language: ${arr[0]}" -
Associative Array Variable:
output=$(venv get user_info --config /home/user/env/config.sh) declare -A user_info while IFS=':' read -r key value; do user_info[$key]=$value done <<< "$output" echo "User Name: ${user_info["name"]}"
-
Regular Variable:
venv delete username --config /home/user/env/config.sh -
Array Variable:
venv delete languages --config /home/user/env/config.sh -
Associative Array Variable:
venv delete user_info --config /home/user/env/config.sh