绕过无法识别的转义序列 [英] Bypass Unrecognized Escape Sequence

查看:76
本文介绍了绕过无法识别的转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我正在写一个SSH包装器,看起来很不错。但是,如果我想发送一个复杂的Unix命令,如下所示,我遇到了这样的问题。



cat / proc / cpuinfo | grep^ cpu MHz。*| awk -F:''{print $ 2}''| sed''s @ \。@@ g''| uniq



我可以通过在双引号中添加\来轻松嵌入字符串中的第一个双引号:



Dear all,

I''m writing a SSH wrapper and things are looking pretty good. However, if I want to send a complex Unix command such as below, I''m running into so problems.

cat /proc/cpuinfo | grep "^cpu MHz.*" | awk -F": " ''{print $2}'' | sed ''s@\.@@g'' | uniq

The first double quote i can easily embed in the string by adding \ to the double quote :

string text = "cat /proc/cpuinfo | grep \"^cpu MHz.*\" | awk -F\": \" ''{print $2}'' | sed ''s@\.@@g'' | uniq";





我添加了a \在\^ cpu MHz。* \的双引号之前。这很好,但我想要逃避整个字符串,如



I added a \ right before the double quote at \"^cpu MHz.*\". That works fine, however I''d like to escape an entire string like

''s@\.@@g'' 





有人可以指出我正确的方向。



干杯并再次感谢你。



Can someone please point me in the right direction.

Cheers and thanks one again.

推荐答案

2}''| sed''s @ \。@@ g''| uniq



我可以通过在双引号中添加\来轻松嵌入字符串中的第一个双引号:



2}'' | sed ''s@\.@@g'' | uniq

The first double quote i can easily embed in the string by adding \ to the double quote :

string text = "cat /proc/cpuinfo | grep \"^cpu MHz.*\" | awk -F\": \" ''{print


2}''| sed''s @ \。@@ g''| uniq;
2}'' | sed ''s@\.@@g'' | uniq";





我在\^ cpu MHz。* \的双引号前加了一个\。这很好,但我想要逃避整个字符串,如



I added a \ right before the double quote at \"^cpu MHz.*\". That works fine, however I''d like to escape an entire string like

''s@\.@@g'' 





有人可以指出我正确的方向。



干杯并再次感谢你。



Can someone please point me in the right direction.

Cheers and thanks one again.


有一篇很好的文章在在C#中转义:字符,字符串,字符串格式,关键字,标识符 [ ^ ]



基本上,您应该可以使用@符号。



例如:



There''s a good article at Escaping in C#: characters, strings, string formats, keywords, identifiers[^]

Basically, you should be able to use the @ symbol.

For example:

String tempVar = @"cat /proc/cpuinfo | grep "^cpu MHz.*" | awk -F": " '{print


这篇关于绕过无法识别的转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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