Quotemire

quotemire
Arguments:

$1… - List of commands in the chain

Output:

stdout - The final conglomeration of all the commands together, ready for eval

Bash CLI version of quotemire

quotemire
Arguments:

$1… - List of commands in the chain

Output:

stdout - The final conglomeration of all the arguments together, ready for eval

When you have to execute a command that calls another command, that calls another command, where to put the quotes can get out of hand after the 3rd or 4th iteration.

Problem Example

ssh server "su - ben -c 'bash -c \"ls -la '\''/tmp/foo bar'\''\"'"

quotemire allows you to instead handle this as this chain of commands as an array of strings, and then it programmatically combines it into one long command

Example

args=()
args[0]="ssh server"
args[1]="su - ben -c"
args[2]="bash -c"
args[3]="ls -la"
args[4]="/tmp/foo bar"

# Or if you want to combine args[3] and args[4]
# args[3]="ls -la '/tmp/foo bar'"

eval "$(quotemire "${args[@]}")"
# or
bash -c "$(quotemire "${args[@]}")"

This chain quoting is only an issue for commands like su -c, bash -c and ssh (because ssh does not handle command arguments correctly). However other commands like env, sudo, etc… do not need this quotation, so should not be made separate arguments:

Mixed Example

args=()
args[0]="$(print_command ssh -t "${@}")"
args[1]="ssh -t -R '${de_socket}:/var/run/docker.sock' ${phone_home}"
args[2]="env 'DOCKER_HOST=unix://${de_socket}' 'DISPLAY="${DISPLAY}"' bash -c"
args[3]="cd '$(pwd)'; exec bash"

In this example, the env and bash are on the same argument, because env does handle multiple arguments for a command correctly