[英]Save variable with command substitution… command not found
I need to save into a bash variable a string after a grep
and sed
treatment. 经过
grep
和sed
处理后,我需要将字符串保存到bash变量中。 Here my code : 这是我的代码:
echo ${plan} | grep -e '^\S' -e 'Home directory:' | sed -e 's/Home directory: //'
/home/james
That's what I need to save into a variable... so I tried : 这就是我需要保存到变量中的内容...所以我尝试了:
HOME_DIRECTORY=$(${plan} | $(grep -e '^\S' -e 'Home directory:') | $(sed -e 's/Home directory: //'))
and 和
HOME_DIRECTORY=`${plan} | grep -e '^\S' -e 'Home directory:' | sed -e 's/Home directory: //'`
But both give me : 但是两者都给我:
line 121: Home: command not found
Change you command to , 将您的命令更改为
HOME_DIRECTORY=$(echo ${plan} | grep -e '^\S' -e 'Home directory:' | sed -e 's/Home directory: //')
That is, you need to include the whole command inside $()
. 也就是说,您需要将整个命令包含在
$()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.