I have a .sh
file:
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:]])}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.