delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT 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:date:from:reply-to:message-id:to:subject | |
:in-reply-to:references:mime-version:content-type | |
:content-transfer-encoding; q=dns; s=default; b=bgyB6YOvWAMh7/Cp | |
JnO7ZMc/a+rxkmlJVwbBZAba+WhJShAgvRHK8B0pbozmcgTkWhOyC+bz1x967kxo | |
h3qsTia/rxcy45Vvdh+K8niWeogEGOj9EKU5Z73aX7PwphFMOr9+RjQvxujQQfdX | |
QA09hFTVBjVhtipUAs0k7cimu00= | |
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:date:from:reply-to:message-id:to:subject | |
:in-reply-to:references:mime-version:content-type | |
:content-transfer-encoding; s=default; bh=p/BcgbuGeSZ4YFkVblxyx3 | |
ORjGk=; b=XDGsgQCzXJYwmH+bMpani2+dZDj/N8YQRfrsPk7qWVCtpi3bplDBjk | |
bW/TW7LYlnNf8VnvIG3dwyRl7htsUiSPeOTGKBIbEYetiZxDYrznOSbLXMBxZkn+ | |
pERKj1eMbTswPpJpoV/QamWWWplsOK/XHYGf7IdRgQKrLM+8FWc9M= | |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
Authentication-Results: | sourceware.org; auth=none |
X-Virus-Found: | No |
X-Spam-SWARE-Status: | No, score=3.2 required=5.0 tests=BAYES_80,FREEMAIL_FROM,KAM_THEBAT,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=terrible, andrey, Repin, repin |
X-HELO: | forward2o.cmail.yandex.net |
Authentication-Results: | smtp2j.mail.yandex.net; dkim=pass header.i=@yandex.ru |
X-Yandex-Suid-Status: | 1 0,1 0 |
Date: | Wed, 7 Sep 2016 20:27:42 +0300 |
From: | Andrey Repin <anrdaemon AT yandex DOT ru> |
Reply-To: | cygwin AT cygwin DOT com |
Message-ID: | <15510127987.20160907202742@yandex.ru> |
To: | Kipton Moravec <kipton_moravec AT yahoo DOT com>, cygwin AT cygwin DOT com |
Subject: | Re: Bash shell script issue |
In-Reply-To: | <1709131555.354781.1473264514358@mail.yahoo.com> |
References: | <330568691 DOT 2384551 DOT 1473201409220 DOT ref AT mail DOT yahoo DOT com> <330568691 DOT 2384551 DOT 1473201409220 AT mail DOT yahoo DOT com> <c0b897be-d3cf-f3b9-cf5b-0024a1d395e5 AT redhat DOT com> <1709131555 DOT 354781 DOT 1473264514358 AT mail DOT yahoo DOT com> |
MIME-Version: | 1.0 |
X-IsSubscribed: | yes |
Greetings, Kipton Moravec! > dalkmora AT 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? Put quotes around any variable expansion you are not in control of. > I was taking the example from a shell script I found. > So I added quoting on the echo: > #!/bin/bash > echo "$PWD" Good. > project_root=$PWD Still bad. > echo "$project_root" Good. > x=${project_root}/tools Still bad. > echo "$x" > echo "${x}" | cat -A Good. > dalkmora AT 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. "^M" == \r == CR (Carriage Return) Switch your N++ to "LF only" line endings. > dalkmora AT DALM0048 ~/walnut/dp2b_walnut_customer_flextronics/walnut > $ d2u testconvert1.sh > dos2unix: converting file testconvert1.sh to Unix format... > dalkmora AT 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? Because of the incorrect line endings. When you assign "project_root=$PWD", you're, in fact, assigning "project_root=$PWD\r" Same for x and for the case where you quote part of the string. project_root="$PWD"\r is treated the same as project_root="$PWD\r" There's one way to force end of line before EOL, but I won't tell you to not promote bad behavior. What d2u did is removed these bogus CR characters and your script now works as expected. > I can understand the confusion at the end of the line. But there was none > shown in the middle from od command. It was inherited from previous assignment. P.S. Also, "insufficient quoting" issue is unrelated to incorrect line endings and is meant to prevent ambiguous assignments like x="Hello; echo rm -rf /" y=$x -- With best regards, Andrey Repin Wednesday, September 7, 2016 20:14:46 Sorry for my terrible english... -- 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
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |