0

Hi guys I am trying to write a shell script which installs java and sets the paths for it.

For this I was trying to get the root folder where I have installed Java. I successfully did so by using grep command. My java home directory is like this /usr/bin/java. I obtained usr directory separately. Now I want to add /usr string literal to a variable. But it's just adding usr with a white space before it.. Can anyone help me out with this.

Here is the example I'm giving not the real one though...

directory="/usr/bin/java"
echo $directory
IFS=/
set $directory
echo /$2
t=$'/'$2
echo $t
4

1 回答 1

1

Under , you could simply:

directory="/usr/bin/java"
set -- ${directory//\// }
echo /$3

will print:

/java
于 2013-04-07T08:37:10.367 回答