Quote:
Thank you. |
Quote:
why escape the '>' in the first place? why doesn't it throw an error? |
Code:
[ "$val1" \> "$val2" ] Code:
test "$val1" \> "$val2" An unquoted > would be a redirection to a file, therefor the escape. You can also escape it with Code:
test "$val1" ">" "$val2" This is different in the [[ ]] compound where the shell parser directly handles the operation without prior word splitting or expansion. Code:
[[ $val1 > $val2 ]] |
Does that means I have to quote every instance of the string that contains spaces ?
|
Quote:
Quote:
|
If I remove the escape from it will give error
because the bash think it is an output redirection Quote:
I'm in love with bash scripts and bash tricks |
Quote:
|
Really thanks a lot
|
another advantage to [[ ]] compared to [ ] is what if val1 or val2 were empty or null?
Code:
#cat strtest.sh Code:
#cat strtest.sh |
Empty variables are another reason for the rule:
always quote variables in command arguments, including the [ ] test command. Literal strings that contain a space must always be in quotes. Examples Code:
var=* # assignment, does not need to be quoted. |
thanks for you all
it helped me |
You are welcome.
Go TeamLQ! |
All times are GMT -5. The time now is 07:42 PM. |