嵌套引号 bash [英] Nested quotes bash

查看:29
本文介绍了嵌套引号 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 ?

提前致谢.

推荐答案

只要在远程服务器上的 shell 上执行整个命令字符串之前最初打算扩展变量,您仍然可以放置单引号.

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天全站免登陆