help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Simple echo is printing the wrong value


From: Bill Gradwohl
Subject: Re: [Help-bash] Simple echo is printing the wrong value
Date: Wed, 4 Apr 2012 09:53:22 -0600

On Wed, Apr 4, 2012 at 9:09 AM, Greg Wooledge <address@hidden> wrote:
On Wed, Apr 04, 2012 at 08:54:25AM -0600, Bill Gradwohl wrote:
> for file in *; do
>    echo ${file}
>    func ${file}

This is already wrong.  QUOTES.  THEY ARE NOT OPTIONAL.

echo "$file"
func "$file"


I purposely didn't use double quotes because I wanted it to create 2 passed parameters to the echo statement and 2 passed parameters to the function knowing that the white space character was there. If I put double quotes around it then it only passed 1 parameter, one with a space between the * and the X.

Why do you say it is WRONG. I don't see it being wrong or right except depending on circumstances. If I want 2 passed parameters I can't use double quotes. Therefore quotes are optional depending on circumstances.

That's why I eventually put double quotes around the second version to show only 1 parm is hitting echo and the function. That parm has a space in it.

>    case ${file} in

Now, here you can omit the quotes, because case is one of those places
with special parser rules.


I guess that's it. It's special. Write 2 lines of code and one line gets treated differently from the other. That's idiosyncratic, but I get it - that's the way it is.

--
Bill Gradwohl


reply via email to

[Prev in Thread] Current Thread [Next in Thread]