[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Bash is broken
From: |
Chris F.A. Johnson |
Subject: |
Re: Bash is broken |
Date: |
Sun, 13 May 2007 04:28:47 -0400 |
User-agent: |
slrn/0.9.8.1 (Linux) |
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)
- Re: Bash is broken, Stephane Chazelas, 2007/05/13
- Re: Bash is broken,
Chris F.A. Johnson <=