简体   繁体   English

在java中执行mobile shell命令时,在每个特殊字符之前获得反斜杠

[英]getting backslash before every special character while executing the mobile shell commands in java

Getting backslah "\\" before every specail character while executing the Mobile shell script in java 在java中执行Mobile shell脚本时,在每个specail字符之前获取backslah“\\”

i am trying to run ip addr show $(awk 'NR==3{print $1}' /proc/net/wireless | tr -d :) | 我正在尝试运行ip addr show $(awk'NR == 3 {print $ 1}'/ proc / net / wireless | tr -d :) | awk '/ether/{print $2}' awk'/ ether / {print $ 2}'

to get the wifi address of the device via adb shell but when script get executed then backslash get added before "$" sign. 通过adb shell获取设备的wifi地址但是当脚本执行时,则在“$”符号之前添加反斜杠。

like this Running '/usr/bin/adb -P 5037 -s 711KPSL0621238 shell ip "addr show \\$(awk 'NR==3{print \\$1}' /proc/net/wireless | tr -d :) | awk '/ether/{print \\$2}'"' 像这样运行'/ usr / bin / adb -P 5037 -s 711KPSL0621238 shell ip“addr show \\ $(awk'NR == 3 {print \\ $ 1}'/ proc / net / wireless | tr -d :) | awk '/ ether / {print \\ $ 2}'''

In Java, a character preceded by a backslash ( \\ ) is an escape sequence and has special meaning to the java compiler. 在Java中,以反斜杠(\\)开头的字符是转义序列,对java编译器具有特殊含义。

For example, if you want to put quotes within quotes you must use the escape sequence, \\", on the interior quotes. 例如,如果要将引号放在引号内,则必须在内部引号上使用转义序列\\“。

To print the sentence: He said "Hello!" 打印句子: 他说“你好!” to me. 对我来说。

you should write: 你应该写:

System.out.println("He said \"Hello!\" to me.");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM