[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Incorrect manage "*" in test -z
From: |
Greg Wooledge |
Subject: |
Re: Incorrect manage "*" in test -z |
Date: |
Fri, 17 Apr 2015 08:15:09 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Fri, Apr 17, 2015 at 09:51:04AM +1000, Guillermo Buritica Tobon wrote:
> H have the next bash script code.:
>
> #!/bin/sh
This is not bash. This is sh.
> read INPUT
Avoid using ALL-CAPS variable names. All-caps names are reserved for
internal shell variables, and environment variables like PATH or HOME.
Use at least one lower-case letter in your regular variables.
> if [ -z "$INPUT" ]; then
> echo OK
> else
> echo $INPUT
Never omit the quotes around an expansion unless you KNOW you're doing
it in a context where it's safe. This is not such a context.
echo "$INPUT"
> The ISSUE is when the string Contain "*" the results are very estrange. or
> "*[space]"
This is PRECISELY why you must quote your variable expansions.
If you fail to quote them, the results undergo word splitting and
pathname expansion. This is what you are seeing.
Always quote your variable expansions.
echo "$INPUT"