This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bash shell script issue


On 09/07/2016 12:27 PM, Andrey Repin wrote:
>> 243d    707b    6f72    656a    7463    725f    6f6f    7d74 
>> 0000120   /   t   o   o   l   s  \r  \n   e   c   h   o       $   x  \r 

                                   ^^^                                ^^

> 
>> Shows there is not "careless editing". 

Umm, those \r ARE carriage returns, as the result of the careless
editing that converted your file to CRLF endings.  Use d2u to strip them
back out.

>> project_root=$PWD
> 
> Still bad.

No, that one's good.  Quotes are only REQUIRED when you want to ensure
that there is no word splitting or globbing going on, and assignment
context has neither of those.  However, although the quotes are optional
in that context, using them out of habit makes it easier to remember to
use quotes in the contexts where it does matter.

> 
>> echo "$project_root"
> 
> Good.
> 
>> x=${project_root}/tools 
> 
> Still bad.

No, that one's okay.  In fact, if you are going for minimalism, you
could use:

x=$project_root/tools

as the ${} form is only REQUIRED when you are using operators inside {}
or when the next character after } is ambiguous with a continuation of
the name of the variable in after the $.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]