嵌套引号的bash [英] Nested quotes bash

查看:168
本文介绍了嵌套引号的bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要嵌套多个字符串是这样的:

I want to nest multiple strings like this :

sudo ssh server "awk "/pattern/{print "hello"}1" file > file.tmp"

随着2嵌套引用我设法让我的命令如下:

With 2 nested quotes I managed to make my command works :

awk "/pattern/{print \"hello\"}1" file > file.tmp

我不能使用单引号('),因为在我的命令变量。
有人可以帮我吗?

I cannot use single quote (') because there are variables in my command. Can someone help me ?

先谢谢了。

推荐答案

您仍然可以只要变量打算开始扩大在外壳上执行远程服务器上的整个命令字符串前放置单引号。

You can still place single quotes as long as the variables are intended to be initially expanded before the whole command string is executed on the shell on the remote server.

sudo ssh server "echo \"$SOMEVAR\"; awk '/pattern/{print \"hello\"}1' file > file.tmp"

这篇关于嵌套引号的bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆