X-Recipient: archive-cygwin@delorie.com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:reply-to:subject:references:to:from:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; q=dns; s=default; b=JKNI6kmUitmIg9W1
	4oHZk7beaBoi3v6MeCKCT2sqRf/nO/krBWsgY/bRzJbfRPrM2iTDFU04Ul3gPqNz
	1vWfhfIcB+CjdBo9xQE0hA8O2cQQeAalgRdQr5DhxtNh7thnPt88edipFTRHTrvY
	UUUP5dcUSOYSRYF/AJDgW1813sQ=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
	:list-unsubscribe:list-subscribe:list-archive:list-post
	:list-help:sender:reply-to:subject:references:to:from:message-id
	:date:mime-version:in-reply-to:content-type
	:content-transfer-encoding; s=default; bh=+O+BdQaOw8KasEU3L5IHDh
	g6260=; b=GJeqpY1upvWejxDVTSdMiDc61mKb5XGUFVRt3QIF9a3OJBMtUGMzoS
	d1Q6i2rx9goEjQSbsurd/d6PhsyOoLVLHpqP9+0XdRIKtwibmHIdA75F9flC4bKA
	eo2gmWTEulbCTsgKzohQz3hi22VQVUWNhhCINxhffzf5Yvuaxe2N0=
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=1.0 required=5.0 tests=AWL,BAYES_50,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 spammy=5024, 6863, 2123, 0000140
X-HELO: smtp-out-no.shaw.ca
X-Authority-Analysis: v=2.2 cv=eo2d9chX c=1 sm=1 tr=0 a=WqCeCkldcEjBO3QZneQsCg==:117 a=WqCeCkldcEjBO3QZneQsCg==:17 a=IkcTkHD0fZMA:10 a=L2GSFO1qK-mqEVvm4voA:9 a=QEXdDO2ut3YA:10
Reply-To: Brian.Inglis@SystematicSw.ab.ca
Subject: Re: Bash shell script issue
References: <330568691.2384551.1473201409220.ref@mail.yahoo.com> <330568691.2384551.1473201409220@mail.yahoo.com> <c0b897be-d3cf-f3b9-cf5b-0024a1d395e5@redhat.com> <1709131555.354781.1473264514358@mail.yahoo.com>
To: cygwin@cygwin.com
From: Brian Inglis <Brian.Inglis@SystematicSw.ab.ca>
Message-ID: <91b97490-5440-39bd-1940-68994a0ec62a@SystematicSw.ab.ca>
Date: Wed, 7 Sep 2016 13:16:12 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
MIME-Version: 1.0
In-Reply-To: <1709131555.354781.1473264514358@mail.yahoo.com>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-CMAE-Envelope: MS4wfCrYFTm4YyagofumQnntf7Z6UgQ33oR4nGsLtLvEnLFgBLeDl0EdSSvJddqcGtXYMTvgEja9yahq77j4N+3NxC/X5fHKEXOqIFiqwvaTnLYRQgeaL7Yl OKbE11aPinzmn5FI2Qmr45y/0Erb5BUDu3TR8r44hBjmYAtwCB9EOW2eh41rmLe7jXNYK2pYi41oxw==
X-IsSubscribed: yes

On 2016-09-07 10:08, Kipton Moravec wrote:
>> From: Eric Blake
>> On 09/06/2016 05:36 PM, Kipton Moravec wrote:
>>> I this is the script:
>>> #!/bin/bash
>>> echo $PWD
>> Insufficient quoting. This does not do the right thing if $PWD contains
>> spaces.  But not necessarily related to your problem at hand.
>>> project_root=$PWD
>>> echo $project_root
>> Again, insufficient quoting.
>>> x=${project_root}/tools
>>> echo $x
>> And again.
>>> echo ${x} | cat -A
>>> On original Windows 7 computer I get:
>>> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
>>> $ ./testconvert1.sh
>>> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
>>> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
>>> /toolsdalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
>>> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut^M/tools^M$
>> The carriage returns are likely a product of you editing the file in
>> text mode (Windows notepad is notorious for this, but many other native
>> programs do likewise), but trying to execute the script in binary mode
>> (the default, if you do not use 'set -o igncr').
>>> What am I doing wrong or is this an error?
>>> Where do the carriage returns (^M) come from, and how do I get rid of them?
>> d2u /path/to/your/script
>> to remove all the carriage returns from your careless editing. Once they
>> are gone, then you don't need the 'igncr' crutch to tell bash to go into
>> text mode.
> As I said I am new to shell scripting. I have been programming
>microcontrollers, bare bones with no OS for most of the past 40 years.
> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
> $ od -cx testconvert1.sh
> 0000000   #   !   /   b   i   n   /   b   a   s   h  \r  \n   e   c   h
> 2123    622f    6e69    622f    7361    0d68    650a    6863
> 0000020   o       $   P   W   D  \r  \n   p   r   o   j   e   c   t   _
> 206f    5024    4457    0a0d    7270    6a6f    6365    5f74
> 0000040   r   o   o   t   =   $   P   W   D  \r  \n   e   c   h   o
> 6f72    746f    243d    5750    0d44    650a    6863    206f
> 0000060   $   p   r   o   j   e   c   t   _   r   o   o   t  \r  \n   x
> 7024    6f72    656a    7463    725f    6f6f    0d74    780a
> 0000100   =   $   {   p   r   o   j   e   c   t   _   r   o   o   t   }
> 243d    707b    6f72    656a    7463    725f    6f6f    7d74
> 0000120   /   t   o   o   l   s  \r  \n   e   c   h   o       $   x  \r
> 742f    6f6f    736c    0a0d    6365    6f68    2420    0d78
> 0000140  \n   e   c   h   o       $   {   x   }       |       c   a   t
> 650a    6863    206f    7b24    7d78    7c20    6320    7461
> 0000160       -   A
> 2d20    0041
> 0000163
> Shows there is not "careless editing".
> So "Insufficient quoting" means nothing to me. How should it be?
>I was taking the example from a shell script I found.
> So I added quoting on the echo:
> #!/bin/bash
> echo "$PWD"
> project_root=$PWD
> echo "$project_root"
> x=${project_root}/tools
> echo "$x"
> echo "${x}" | cat -A
> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
> $ ./testconvert1.sh
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /toolsdalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut^M/tools^M$
> No difference.
> So maybe in the commands?
> #!/bin/bash
> echo "$PWD"
> project_root="$PWD"
> echo "$project_root"
> x="${project_root}"/tools
> echo "$x"
> echo "${x}" | cat -A
> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
> $ ./testconvert1.sh
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /toolsdalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut^M/tools^M$
> Again no difference.
> So finally I looked up d2u
> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
> $ d2u testconvert1.sh
> dos2unix: converting file testconvert1.sh to Unix format...
> dalkmora@DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut
> $ ./testconvert1.sh
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut/tools
> /home/dalkmora/walnut/dp2b_walnut_customer_flextronics/walnut/tools$
> That fixed it, but I still do not understand it.
> Why are there ^M (carriage return) in the middle of a line?
>I can understand the confusion at the end of the line.
>But there was none shown in the middle from od command.

od does not dump lines, it dumps blocks of bytes, 16 per line in the above
case, and there every \n <NL/LF/^J/ctrl-J> is preceded by \r <CR/^M/ctrl-M>:
TTY line terminators, used by Windows; Unix, Cygwin, and OS X Darwin use
Multics line terminators \n <NL/LF/^J/ctrl-J>; native Mac OS X apps use \r
<CR/^M/ctrl-M> like Apple I.

If you have to use od, try od -Ax -tx1z ... for split hex/text output, or
install xxd hexdump utility from Cygwin packages (part of vim, but packaged
separately), and use xxd -g1 ...
[really: octal dump, and short words; how many decades has it been since
anyone used non-binary-multiple bytes? I know RMS (and I) grew up using
octal and 6, 7, and 9 bit characters, but seriously time to let go... ;^> ]

Googling 'notepad++ Unix format', summarizing boxed first hit:
Edit > EOL Conversion > Unix Format.

Googling 'notepad++ hex view' displays:
View > Show Symbols > Show all characters.

Finally, go native - install and learn emacs or vim - but never ask which! ;^>

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

