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:to:message-id:in-reply-to :references:subject:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=worgFWGU03Wmc1S2 Z4mcsNDyR5QjrTjZEDw6ZtGAnVum1wl2MJDhmDHKTMJTIFcgp7mZLW50F6g6rlnL jYr18AIgWGbVtQMJv18kBiJs2ss+A0p5smKoF5MJje52v4z8cf4wJKE/791Q3M96 ko4pmklDRsFK9gyKIASFQv8+ASM= 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:to:message-id:in-reply-to :references:subject:mime-version:content-type :content-transfer-encoding; s=default; bh=sKH/tFBC2UxiUayceLp5LY vAH3M=; b=YMDNjmEwHTsy2CHby3M1mWo/MMfHmAaL8a4JKTao4H+kwBwOKxWjVz 1p9UudHXcVuaphJS1wsZL+lJRBEquOBtxLgLqnURaFItuD4cWzNWtjAyf6/6av18 ETzk4w/x6MyvRXQDSU4nwsrj7bx1VHTHpou2yahNieHwbmP4fR28Q= Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , 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=1.5 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RCVD_IN_SORBS_SPAM,RP_MATCHES_RCVD,SPF_PASS autolearn=no version=3.3.2 spammy=eblakeredhatcom, eblake AT redhat DOT com, U*kipton_moravec, kipton_moravecyahoocom X-HELO: nm41-vm8.bullet.mail.ne1.yahoo.com Date: Wed, 7 Sep 2016 16:08:34 +0000 (UTC) From: Kipton Moravec Reply-To: Kipton Moravec To: Eric Blake , "cygwin AT cygwin DOT com" Message-ID: <1709131555.354781.1473264514358@mail.yahoo.com> In-Reply-To: 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> Subject: Re: Bash shell script issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes 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 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? 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 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. 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 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$ Again no difference. So finally I looked up d2u 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? I can understand the confusion at the end of the line. But there was none shown in the middle from od command. Kip ----- Original Message ----- From: Eric Blake To: cygwin AT cygwin DOT com; kipton_moravec AT yahoo DOT com Sent: Tuesday, September 6, 2016 8:21 PM Subject: Re: Bash shell script issue 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 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$ 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. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org -- 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