不需要反引号的运行ssh复杂远程命令方式

Posted by 4Aiur on 2010/06/07 in Shell |

不需要反引号的运行ssh复杂远程命令方式

之前当我需要执行复杂的运程命令时,总是要先处理好引号、变量等问题,之后再执行命令写起来太麻烦,今天在commandlinefu上学了一招非常棒的方法,记录一下。

举个例子,之前需要用\反引$符号

现在我们可以把复杂的命令写到文件中执行。

方法1:

方法2:

方法3,使用标准输入执行,输入完毕后使用ctrl-D提交命令:

直接把script嵌入到脚本中

来源: http://www.commandlinefu.com/commands/view/5772/run-complex-remote-shell-cmds-over-ssh-without-escaping-quotes

run complex remote shell cmds over ssh, without escaping quotes Much simpler method. More portable version:

run complex remote shell cmds over ssh, without escaping quotes

I was tired of the endless quoting, unquoting, re-quoting, and escaping characters that left me with working, but barely comprehensible shell one-liners. It can be really frustrating, especially if the local and remote shells differ and have their own escaping and quoting rules. I decided to try a different approach and ended up with this.

so we need to save the command in cmd.txt first and then run it?

there’s no way to do this? :

one alternative I can think of (not to save a file and then use “cat cmd.txt”) is;

And then type your command, press Enter and then ctrl-D. This will allow you run complex commands on remote machine without saving a file..

Tags: ,

Copyright © 2010-2017 4Aiur All rights reserved.
This site is using the Desk Mess Mirrored theme, v2.5, from BuyNowShop.com.

.