Bash shell script issue
Eric Blake
eblake@redhat.com
Wed Sep 7 18:28:00 GMT 2016
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20160907/4aadd7a1/attachment.sig>
More information about the Cygwin
mailing list