I'm writing a script that will ssh to a number of hosts and run commands. I'm a bit stumped at the moment as some of the commands that I need to run contain wildcards (i.e. *), and so far I have not figured out how to escape the * character so the script doesn't expand it. More specifically, here's an excerpt of the script.
Let's say I'm trying to pass a command some_command * options to the script. No matter how I tried escaping the *, $@ variable always converts it to the list of files. Any ideas on how to fix this?
Nope, still doesn't work... I tried that one as well. It doesn't expand the file list anymore, but then I have the backslash as part of my variable (see below for an example).
I'm not sure it's the shell that's expanding the variable:
As previously stated in an ssh script, the commands ( and eventually all the special characters in them, for example: *, $, ...) will be evaluated first by the current shell, before ssh-in.
So you need to properly escape all of them. For more check these threads: