Skip to main content
added 1 character in body
Source Link
user3379410
  • 176
  • 1
  • 11

I want to extract the output of a command run through shell script in a variable but I am not able to do it. I am using grep command for the same. Please help me in getting the desired output in a variable.

x=$(pwd)
pw=$(grep '\(.*\)/bin' $x)
echo "extracted is:"
echo $pw

The output of the pwd command is /opt/abc/bin/ and I want only /root/abc part of it. Thanks in advance.

I want to extract the output of a command run through shell script in a variable but I am not able to do it. I am using grep command for the same. Please help me in getting the desired output in a variable.

x=$(pwd)
pw=$(grep '\(.*\)/bin' $x)
echo "extracted is:"
echo $pw

The output of the pwd command is /opt/abc/bin and I want only /root/abc part of it. Thanks in advance.

I want to extract the output of a command run through shell script in a variable but I am not able to do it. I am using grep command for the same. Please help me in getting the desired output in a variable.

x=$(pwd)
pw=$(grep '\(.*\)/bin' $x)
echo "extracted is:"
echo $pw

The output of the pwd command is /opt/abc/bin/ and I want only /root/abc part of it. Thanks in advance.

Source Link
user3379410
  • 176
  • 1
  • 11

Extracting group from regex in shell script using grep

I want to extract the output of a command run through shell script in a variable but I am not able to do it. I am using grep command for the same. Please help me in getting the desired output in a variable.

x=$(pwd)
pw=$(grep '\(.*\)/bin' $x)
echo "extracted is:"
echo $pw

The output of the pwd command is /opt/abc/bin and I want only /root/abc part of it. Thanks in advance.