LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script gives weird output (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-gives-weird-output-927936/)

jonaskellens 02-18-2012 06:58 AM

The following is a good if-then-else :

if [[ $Number -eq 0 ]]; then

catkin 02-18-2012 11:31 AM

Quote:

Originally Posted by jonaskellens (Post 4605782)
Number=${Number/ /} removes white spaces

It removes spaces. Your previous version, ${Number//[[:space:]]}, removes whitespace. Whitespace is any of the characters space, tab and newline.

EDIT: actually ${Number/ /} removes only the first space. ${Number// /} removes all spaces and can be more simply given as ${Number// }. Here's a command prompt illustration:
Code:

c@CW8:~$ x=' a b c '
c@CW8:~$ echo "'${x/ /}'"
'a b c '
c@CW8:~$ echo "'${x// /}'"
'abc'
c@CW8:~$ echo "'${x// }'"
'abc'



All times are GMT -5. The time now is 02:23 AM.