delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2016/12/06/00:00:33

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:from:to:subject:date:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; q=dns; s=default; b=tYBEXkWBrKf64wOcFpnhZh6ypOUZw
7a/fw2Up4MGnOGX+J2A6uAjBaHSdxV53qSRbNsu0movP9E47eBa6FG7Imnlc4bLd
9rO1tsB57xICCQ5g8poz07i7xK+qnnowHXdLr+JkZvZHcxSFx0bsoLrWBBFOx31D
0uCIkFx0iE3+Ys=
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:from:to:subject:date:message-id:references
:in-reply-to:content-type:content-transfer-encoding
:mime-version; s=default; bh=rYZNZgwkQPBMtrPk4CtW8Huykjo=; b=B7s
/OMz9O07FQki5UyEiLWsZimZgTKI5VRk8FqAHHaU2YnHG4Ft/tNdmkAmtrjJSnjd
Md7xZA0Sc+4qSaEAyc3zwodg7S/huKg+g6eVY16OqzYlUObMrZY1O+3wZyfBlbau
j366GVWy1Q6qK7gcSIbTqUA66NR2E6awvpyjtjBk=
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=4.1 required=5.0 tests=BAYES_50,CYGWIN_OWNER_BODY,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=no version=3.3.2 spammy=disaster, glenn, Glenn, sk:briani
X-HELO: esa1.dell-outbound.iphmx.com
From: "Gluszczak, Glenn" <Glenn DOT Gluszczak AT dell DOT com>
X-DKIM: OpenDKIM Filter v2.4.3 mailuogwprd51.lss.emc.com uB64wGsH028778
X-DKIM: OpenDKIM Filter v2.4.3 mailuogwprd51.lss.emc.com uB64wGsH028778
To: "Brian DOT Inglis AT SystematicSw DOT ab DOT ca" <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>,
"cygwin AT cygwin DOT com" <cygwin AT cygwin DOT com>
Subject: RE: sh -c and newline
Date: Tue, 6 Dec 2016 04:57:59 +0000
Message-ID: <91DCAC3CB99C724EB365BB64677FBE7B102A65@MX204CL04.corp.emc.com>
References: <91DCAC3CB99C724EB365BB64677FBE7B1007BC AT MX204CL04 DOT corp DOT emc DOT com> <e2de2246-20ad-308b-e6b1-20804163ef51 AT SystematicSw DOT ab DOT ca> <91DCAC3CB99C724EB365BB64677FBE7B100851 AT MX204CL04 DOT corp DOT emc DOT com>,<0ac85458-01dd-7f0f-d6ad-25cbb672d785 AT SystematicSw DOT ab DOT ca>
In-Reply-To: <0ac85458-01dd-7f0f-d6ad-25cbb672d785@SystematicSw.ab.ca>
MIME-Version: 1.0
X-Sentrion-Hostname: mailusrhubprd01.lss.emc.com
X-RSA-Classifications: public
X-IsSubscribed: yes
X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id uB650UfM007975

Ah I never knew about ^.  Thanks a lot for that tip.  I'll try it out tomorrow.

Yeah I work in the backup/data protection division here,
________________________________________
From: cygwin-owner AT cygwin DOT com [cygwin-owner AT cygwin DOT com] on behalf of Brian Inglis [Brian DOT Inglis AT SystematicSw DOT ab DOT ca]
Sent: Monday, December 05, 2016 6:30 PM
To: cygwin AT cygwin DOT com
Subject: Re: sh -c and newline

On 2016-12-05 14:11, Gluszczak, Glenn wrote:
> On 2016-12-05 15:04, Brian Inglis wrote:
>> On 2016-12-05 12:38, Gluszczak, Glenn wrote:
>>> I can't seem to get sh -c to recognize newline. Tcsh -c works.
>>> I'm using echo as an example but I'm actually trying to build a
>>> here-document.
>>> %%%sh -c  "echo \nhello"
>>> nhello
>>> %%%sh -c  "echo \\nhello"
>>> nhello
>>> %%%sh -c  "echo \\\nhello"
>>> \nhello
>>> %%%tcsh -c  "echo \nhello"
>>> nhello
>>> %%%tcsh -c  "echo \\nhello"
>>> \nhello
>>> %%%tcsh -c "echo \\\nhello"
>>> hello
>> Your login shell is scanning and interpreting escapes in the input, then the subshell you are running, so you need to quote \n to let echo see it. Builtin echo does not recognize escapes without -e.
>> You can use echo -e, or $ prefix a single quoted string to have the shell interpret the escape sequence.
>> $ sh -c "echo -e '\nhello'"
>>
>> hello
>> $ sh -c "echo $'\n'hello"
>>
>> hello
>> $ sh -c "echo $'\nhello'"
>>
>> hello
> Thank you for the answer Brian. I was trying to show a problem with a
> HERE document and used echo but it is not the exact same issue.
> I forgot about the order of substitution; my original issue is
> similar.
> In CMD, you can't have multiple lines for sh -c but in shell you can
> sh -c "cat -<<EOF
> hello
> EOF"
> Turns out the newlines are being sent, but CMD thinks a command is
> only on one line. Perhaps there is a way to specify multiple lines in
> a cmd prompt.

Use can use & in cmd like ; in bash and && works the same in both;
with conditional and loop constructs in cmd, you can use:
        if|for ... (    command1...
                        command2...
                )
across multiple lines, and you can use ^ in cmd like \ in bash for both
line continuation and escaping.

Learned this stuff porting some shell scripts to cmd for use by folks
on backup or home desktops during Disaster Recovery and migration backup
tests, so they could download and prep data locally, in case any of the
Unix or file servers, or network, to do this automatically and transparently
were inaccessible.

--
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


--
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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019