When doing server maintenance, I often find myself writing multi-level nested commands, so as:
for server in A B C; do sh -c "ssh $server 'mysql db -e \"select where line like \\\"%abc%\\\"\"'&"; done
This may be a contrived example, but it's really the kind of thing I have to do sometimes for some odd, ad-hoc task.
The problem is the quotes. As you go to deeper levels, you have to start escaping the quotes, escaping dollar signs, and escaping the escaping. Using single quotes helps avoid one level, but that's it.
I began working on a solution for myself, inspired by the qq() function in perl, but I thought I'd ask around first: is there a tool, method or framework that will make it easier to write these nested commands without getting bogged down with backslashes?
sh -c ""
that just adds yet another layer of quoting.&
at the end there. This makes all the ssh commands run in parallel.