I have the path /home/bamboo/bamboo-agent-home/xml-data/build-dir/NG-VOSGQL239-JOB1
and would like to get just /home/bamboo/bamboo-agent-home/xml-data/build-dir/
How can I delete the last part of the path if it can be with different lengths by using Bash?
Advertisement
Answer
Using bash regex =~
:
$ var=/home/bamboo/bamboo-agent-home/xml-data/build-dir/NG-VOSGQL239-JOB $ [[ $var =~ .*/ ]] && echo "${BASH_REMATCH[0]}" /home/bamboo/bamboo-agent-home/xml-data/build-dir/