Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm 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 From: ericblake AT comcast DOT net (Eric Blake) To: David Vergin , cygwin AT cygwin DOT com Subject: Re: Trouble Sending Printer Codes from Perl to Printer Date: Fri, 01 Jul 2005 00:13:08 +0000 Message-Id: <070120050013.11675.42C48A94000180BB00002D9B22007340760A050E040D0C079D0A@comcast.net> X-Authenticated-Sender: ZXJpY2JsYWtlQGNvbWNhc3QubmV0 > > $ echo -en "hello\nworld" > hello > world > dvergin AT GatewayM275 /c/bin > $ #Good! The basic approach works on the command line. > #Control codes are interpreted and no trailing newline. > #So I'll try the same thing from perl letting the echo > # command convert the control char. > # (Note different approach farther down) > > $ perl -e 'system(q/echo -en "hello\nworld"/)' > -en hello\nworld > > dvergin AT GatewayM275 /c/bin > $ #Ack! The -en option is treated as text to be echoed. Ah - the classic /bin/sh is not /bin/bash. system() uses /bin/sh, and ash unfortunately doesn't recognize -en as an argument to echo. POSIX recommends using printf, not echo, when you want more control over what system() outputs: $ perl -e 'system(q/printf "hello\0\nworld"/)' | od -tx1 0000000 68 65 6c 6c 6f 00 0a 77 6f 72 6c 64 0000014 Aha - \0 worked, \n was interpreted, and no trailing newline. And by the way, this is not cygwin specific - any use of \ escape sequences as an argument to echo is inherently non-portable across different shells. -- Eric Blake -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/