从进程获取tomcat安装路径

1、变量前后截取

workdir=`ps -ef | grep "catalina.home" | grep -v "grep"`

workdir=${workdir##*catalina.home=}

workdir=${workdir%% *}

echo $workdir


2、grep+awk单行拆分转多行再拆分

ps -ef | grep "catalina.home" | grep -v "grep" | awk '{for ( i=1; i<=NF; i++) print $i}' | grep "catalina.home" | awk -F'=' '{print $2}'


附:

-sh-3.2# ps -ef | grep "catalina.home" | grep -v "grep"

root     29066     1  0 Apr16 ?        00:00:40 /usr/bin/java -Djava.util.logging.config.file=/usr/apache-tomcat-6.0.43/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/apache-tomcat-6.0.43/endorsed -classpath /usr/apache-tomcat-6.0.43/bin/bootstrap.jar -Dcatalina.base=/usr/apache-tomcat-6.0.43 -Dcatalina.home=/usr/apache-tomcat-6.0.43 -Djava.io.tmpdir=/usr/apache-tomcat-6.0.43/temp org.apache.catalina.startup.Bootstrap start

-sh-3.2# 


你可能感兴趣的:(grep,awk)