VSI Common

Contents:

  • J.U.S.T. Useful Simple Tasking
  • Linux Utilities
    • Executable Aliases
    • Ask Question
    • Bash Utils
    • Binary Utilities
    • Check Shell
    • Circular source
    • Colors Utilities
    • Command Tools
    • Common Source
    • Compatibility Variables
    • Singularity Compatibility Variables
    • CUDA Information
    • Directory Tools
    • Array Manipulation
    • File Tools
    • Find In
    • Find In Paths
    • Git Airgap Submodule Helper
    • Git Commit Description
    • Git Functions
    • Git Mirror
    • Group Names
    • In Is In
    • Is In
    • Linux Accounts
    • Lwhich
    • Mount Tools
    • NVIDIA TOOLS
    • Parser
    • PBDB - Primitive Bash Debugger
    • Picker
    • Pipenv Functions
    • Poratble Patch
    • Postisin
    • Preisin
    • Print Command
    • Python Tools
    • Quotemire
    • Random
    • Real Path
    • Regular Expression Is In
    • Requirements
    • Set Flags
    • String Tools
    • Source once
    • String Tools
    • Time Tools
    • Unwrapping Echo
    • Versions
    • Web Tools
    • Yarp
    • Pyhton Scripts
  • Windows Utilities
  • Unit Tests
  • vsi
  • Get Pipenv
  • pip 8210
  • Docker recipes
  • Contributing Style Guide
VSI Common
  • Linux Utilities
  • Print Command
  • View page source

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:

string_tools.bsh quote_escape

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:
  • string_tools.bsh quote_escape

  • print_command

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
Previous Next

© Copyright 2024, Vision Systems, Inc.

Built with Sphinx using a theme provided by Read the Docs.