This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: sh -c and newline
- From: Brian Inglis <Brian dot Inglis at SystematicSw dot ab dot ca>
- To: cygwin at cygwin dot com
- Date: Mon, 5 Dec 2016 13:03:40 -0700
- Subject: Re: sh -c and newline
- Authentication-results: sourceware.org; auth=none
- References: <91DCAC3CB99C724EB365BB64677FBE7B1007BC@MX204CL04.corp.emc.com>
- Reply-to: Brian dot Inglis at SystematicSw dot ab dot ca
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