I need to save into a bash variable a string after a grep
and sed
treatment. 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 $()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.