checking whitespaces in a string
i want to create a shell script which will take string (for eg: om-23%)as a user input and identifies in case that string contains any spaces (begining/in between characters/end/combination of all of these) of the string
|
yes, do you have a plan or a test version?
|
i have created and tried the below loops but they all failes to detect spaces present at the end of the given string(for eg : om-23%<space><space> )
1. if [ "$string" != "${string% *}" ]; then echo "$string contains one or more spaces"; fi 2. if ( echo "$string" | grep -q ' ' ); then echo 'string contains one or more spaces' exit 1 fi |
actually those spaces are ignored, you can check:
Code:
read a; echo "XX${a}YY" |
All times are GMT -5. The time now is 11:48 AM. |