command line - Bash - how to remove trailing "/bin/java" in commandline? -
i cannot work out, seems command in awk not enough:
basically i'd extract information simple linux ls -l:
ls -l /etc/alternatives/java lrwxrwxrwx. 1 root root 29 apr 5 12:28 /etc/alternatives/java -> /jre/ibm/jdk6sr10fp1/bin/java
i use awk retrieve part:
ls /etc/alternatives/java -l | awk -f"->" '{print $2}' /jre/ibm/jdk6sr10fp1/bin/java
as need remove trailing /bin/java make valid $java_home, how in bash?
all want is:
/jre/ibm/jdk6sr10fp1
many in advance
suppose assigned value /jre/ibm/jdk6sr10fp1/bin/java
java_home
using command substitution:
java_home=$(ls /etc/alternatives/java -l | awk -f"->" '{print $2}')
then can remove trailing part using
java_home=${java_home%/bin/java}
for more information, see, example section manipulating strings
Comments
Post a Comment