* sh -c and newline @ 2016-12-05 19:39 Gluszczak, Glenn 2016-12-05 20:03 ` Brian Inglis 0 siblings, 1 reply; 4+ messages in thread From: Gluszczak, Glenn @ 2016-12-05 19:39 UTC (permalink / raw) To: cygwin 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 -- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: sh -c and newline 2016-12-05 19:39 sh -c and newline Gluszczak, Glenn @ 2016-12-05 20:03 ` Brian Inglis [not found] ` <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com> 0 siblings, 1 reply; 4+ messages in thread From: Brian Inglis @ 2016-12-05 20:03 UTC (permalink / raw) To: cygwin 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 -- 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com>]
* Re: sh -c and newline [not found] ` <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com> @ 2016-12-05 23:30 ` Brian Inglis 2016-12-06 4:59 ` Gluszczak, Glenn 0 siblings, 1 reply; 4+ messages in thread From: Brian Inglis @ 2016-12-05 23:30 UTC (permalink / raw) To: cygwin 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 ^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: sh -c and newline 2016-12-05 23:30 ` Brian Inglis @ 2016-12-06 4:59 ` Gluszczak, Glenn 0 siblings, 0 replies; 4+ messages in thread From: Gluszczak, Glenn @ 2016-12-06 4:59 UTC (permalink / raw) To: Brian.Inglis, cygwin 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@cygwin.com [cygwin-owner@cygwin.com] on behalf of Brian Inglis [Brian.Inglis@SystematicSw.ab.ca] Sent: Monday, December 05, 2016 6:30 PM To: cygwin@cygwin.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 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-12-06 4:59 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2016-12-05 19:39 sh -c and newline Gluszczak, Glenn 2016-12-05 20:03 ` Brian Inglis [not found] ` <91DCAC3CB99C724EB365BB64677FBE7B100851@MX204CL04.corp.emc.com> 2016-12-05 23:30 ` Brian Inglis 2016-12-06 4:59 ` Gluszczak, Glenn
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).