Victoria Seniuk
Victoria Seniuk

Reputation: 1414

How to cut all tabulations and whitespaces Linux shell?

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?

Upvotes: 1

Views: 883

Answers (2)

pmod
pmod

Reputation: 11007

You can also do this using shell parameter expansion approach (described here):

shopt -s extglob

${APP_SERVER_HOME##+([[:blank:]])}  

Upvotes: 2

David Conrad
David Conrad

Reputation: 16379

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.

Upvotes: 3

Related Questions