Article 5SX9G check leading and trailing white space from a variable and fail the script

check leading and trailing white space from a variable and fail the script

by
dilip_d21
from LinuxQuestions.org on (#5SX9G)
Hi All ,

I was trying this for some time and can one one please help , consider variable called release has some value called 1.0.11 , i want to check that variable if it has any leading or trailing space and in case if it has any space then the script should fail , how can i achieve this ??

I tried the below code but this does not work

release=1.0.11

```if [ release=${release// } ]; then
echo "release version has trailing or leading whitespaces"
exit 1
else
echo "release version value is fine"
fi```

Any help much appreciatedlatest?d=yIl2AUoC8zA latest?i=AswtaHNOKzU:o7tH5u1dVR4:F7zBnMy latest?i=AswtaHNOKzU:o7tH5u1dVR4:V_sGLiP latest?d=qj6IDK7rITs latest?i=AswtaHNOKzU:o7tH5u1dVR4:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments