On 2007-05-13, Overdorf, Sam wrote:
> The following does not work on my computers:
>
>  
>
> If [ "1" > "2" ]
>
>   then
>
>     echo "greater"
>
>   else
>
>     echo "not greater"
>
> fi
>
>  
>
> Bash thinks this is I/O redirection and creates a file by the name of
> "2" in my directory.
>
> This should be a string compare.

   As '[' is a command, the arguments are parsed normally, and '>' is
   taken as a redirection operator. (And 'if' should not be
   capitalized.)

   To use '>' in a string comparison, either use the shell syntax [[
   ... ]] or escape the '>':

if [ "1" \> "2" ]

if [[ "1" > "2" ]]

-- 
   Chris F.A. Johnson                      <http://cfaj.freeshell.org>
   ===================================================================
   Author:
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)


_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash

Reply via email to