I have a .sh
开发者_StackOverflowfile:
test -e "$APP_SERVER_HOME"
if [ $? != 0 ]; then
echo "Application server home $APP_SERVER_HOME does not exist"
exit 6
fi
How to cut all whitespaces and tabulations from APP_SERVER_HOME
variable before test command?
APP_SERVER_HOME=`echo "$APP_SERVER_HOME" |sed 's/\s//g'`
Is this what you want?
Note: If it contained " C:\Program Files\Foo\bar.exe " it will now contain "C:\ProgramFiles\Foo\bar.exe" which is probably not what you want.
APP_SERVER_HOME=`echo "$APP_SERVER_HOME" |sed 's/^\s\+//' |sed 's/\s\+$//'`
This one will just trim the leading and trailing whitespace, not internal spaces.
You can also do this using shell parameter expansion approach (described here):
shopt -s extglob
${APP_SERVER_HOME##+([[:blank:]])}
精彩评论