This is the mail archive of the
mailing list for the Cygwin project.
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
>>> %%%sh -c "echo \nhello"
>>> %%%sh -c "echo \\nhello"
>>> %%%sh -c "echo \\\nhello"
>>> %%%tcsh -c "echo \nhello"
>>> %%%tcsh -c "echo \\nhello"
>>> %%%tcsh -c "echo \\\nhello"
>> 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'"
>> $ sh -c "echo $'\n'hello"
>> $ sh -c "echo $'\nhello'"
> 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
> In CMD, you can't have multiple lines for sh -c but in shell you can
> sh -c "cat -<<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...
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
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple