Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我们怎样才能在“中”中找到一个词;使用shell脚本的双引号_Shell_Substring - Fatal编程技术网

我们怎样才能在“中”中找到一个词;使用shell脚本的双引号

我们怎样才能在“中”中找到一个词;使用shell脚本的双引号,shell,substring,Shell,Substring,有一句话:你好。从这个句子中,我需要得到变量中双引号中的单词。。。。 这意味着你应该如何在变量中 如何在shell脚本中实现这一点?您只需使用斜杠“\”在字符串中添加引号 用这个 echo " Hai \"how are you\" " | cut -d'"' -f2 您可以尝试使用grep将所需文本保存在变量中(例如,x) kent$ x=$(echo 'Hai "how are you"'|grep -Po '"\K[^"]+') kent$ echo $x how are yo

有一句话:你好。从这个句子中,我需要得到变量中双引号中的单词。。。。 这意味着你应该如何在变量中
如何在shell脚本中实现这一点?您只需使用斜杠“\”在字符串中添加引号

用这个

 echo " Hai \"how are you\" " | cut -d'"' -f2

您可以尝试使用grep将所需文本保存在变量中(例如,
x

kent$  x=$(echo 'Hai "how are you"'|grep -Po '"\K[^"]+')  
kent$  echo $x
how are you