Print Command
- print_command
- Arguments:
$1
… - List of command + arguments to be echoed- Output:
stdout - A quote escaped version of the command + arguments, ready for
eval
Bash CLI version of print_command
- print_command
- Arguments:
$1
… - List of command + arguments to be echoed- Output:
stdout - A quote escaped version of the command + arguments, ready for
eval
- Uses:
Accurately echoes out a properly escaped single string representation of a command + arguments.
Example
print_command this is a t\ e\ \ s\'\"t
# Results in
this is a 't e s'"'"'"t'
# Typical usage
eval "$(print_command "${stuff[@]}")"
or
bash -c "$(print_command "${stuff[@]}")"
See also
print_command_env
Version that captures changes in the environment
- print_command_save_env
Sets the saved version of the environment, to compare with when calling print_command_env
print_command_env
needs a before version of the environment, to compare with so it will know which environment variables changes. The only “optional variable assignments” or exported variables that will not be captures, are ones set the same value they already have.
- print_command_env
- Arguments:
$1
… - List of command + arguments to be echoed- Output:
stdout - A quote escaped version of the command + arguments, ready for
eval
- Uses:
Accurately echoes out a properly escaped single string representation of a command + arguments, including any “optional variable assignments” and exported environment variables.
When print_command_save_env
is called, the environment is saved and any changes made to the environment from then on, are captures in a call to print_command_env
Example
export A=1
export B=2
function foo()
{
${DRYRUN} some command ${@+"${@}"}
}
print_command_save_env
export DRYRUN=print_command
# ...
foo -e q=5
# some command -e q=5
A=2 foo -t
# A=2 some command -t
B=2 foo -f
# some command -f
unset A; foo -y
# (unset A; some command -y)
export A=1
export C=4
foo c
# C=4 some command c