4/18/2024 0 Comments Ubuntu batch script exampleMore complicated commands often need to be modified (especially if they include double-quotes) to prevent the local interpreter from interfering. Which mechanism is responsible for replacing multiple spaces with just one depends on which quotes you omit. Omitting any pair of quotes will result in hello, world. Then on the remote side the single-quotes makes the remote shell not split the (shorter) string, so echo gets it with these spaces. Here the double-quotes make cmd.exe not split the string, so ssh gets it with these spaces. If you need multiple spaces between the two then this is what you should do: ssh -T "echo 'hello, world'" It will print them as hello, world because injecting a single space is what the tool does in such circumstances. On the remote side echo will get two arguments: hello, and world. Note when you said "seeing echo as the command and the rest as the argument", it's not exactly what happens. The remote shell will get: echo hello, world This is what you intended in the first place. Will pass the following arguments to ssh: -T,, echo hello, world. Solution for uncomplicated commands: use double-quotes, they will be interpreted by cmd.exe. In your case the two parts ( 'echo hello, world') gave this code to run in a remote shell: 'echo hello, world' If there are two or more parts then ssh will build a command for a remote shell by concatenating them, injecting single spaces in between. Following arguments (if any) are also considered parts of the command. Single-quotes got to the tool literally.Īn argument to ssh, that is not recognized as an option, option-argument or is considered to be a command or a part of it. This means your ssh got the following arguments: -T,, 'echo hello, world'. Single quotes are not used at all by the cmd.exe command processor except to enclose the command to run within a FOR /F statement I cannot explain the behavior of the script but I can explain this: has an excellent solution to just put the shell script on the Linux machine. Not using quotes or using double quotes provides the expected behavior. I was using single quotes, but that is strict quoting where everything except for ' is a literal. After the feedback, for the remainder of the debugging I used -delimited has inadvertently pointed out and has noticed that my quoting in 1 is incorrect. Kamil has a very in-depth explanation, including how echo works. It never moves past the if conditional if it even makes it that far. This attempt appears to SSH, complete the first 2 commands, and then hang on the if statement indefinitely. The command seems to parse as one token instead of seeing echo as the command and the rest as the argument. Ssh -T 'echo hello, world' gives bash: echo hello, world: command not found Giving ssh the bash commands directly andĪlternatively pointing ssh at a. To do this I will use batch scripts that send commands over SSH. I want to have a simple way of running commands on a remote Linux machine from local Windows machines.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |