[nycbug-talk] nifty(1)
Matthew Story
matthewstory at gmail.com
Wed Feb 29 10:31:19 EST 2012
On Wed, Feb 29, 2012 at 10:24 AM, Henry M <henry95 at gmail.com> wrote:
> A cool one I came across by accident. A fun way to create a plain text
> file. Redirect stdout of cat to a file, type your text, then close it with
> ctrl-d
>
sh(1) binds stdin to tty if there is nothing on stdin, e.g.:
$ xargs echo
hi
you
guys
^Dhi you guys
$ grep foo
bar
baz
foo
foo
^D
This is also how ed(1) works ... ! Very nifty indeed.
> Sample:
>
>> $ cat >filename
>> Hello, Talk
>> ^D
>> $ cat filename
>> Hello, Talk
>>
>
> Regards,
> -Henry
>
> On Thu, Dec 15, 2011 at 9:24 PM, William Baxter <
> web-nycbug at superscript.com> wrote:
>
>> Excerpts from Matthew Story's message of Thu Dec 15 00:54:24 -0500 2011:
>> > i believe the most portable version is slightly uglier:
>> >
>> > On Dec 14, 2011, at 6:13 PM, Isaac Levy wrote:
>> >
>> > > shout() { echo "$0: $*" >&2; }
>> > > barf() { shout "$*"; exit 111; }
>> > safe() { ${1+"$@"} || barf "cannot $*"; }
>> > ^^^^^^^^ this bit is more reliable for sh on Solaris (real
>> Bourne shell)
>> >
>>
>> Delightful as the topic of Solaris compatibility may be I don't think
>> it's worth
>> going that far. The ${1+"$@"} construct is indispensable for
>> compatibility in
>> cases when an empty list is legitimate while an unintended empty argument
>> is
>> not:
>>
>> for ${1+"$@"}
>>
>> versus
>>
>> for "$@"
>>
>> But an empty string and an empty list are both erroneous for safe().
>> While the
>> execution details may vary from shell to shell, I consider it a case of
>> pilot
>> error to pass in either an empty argument or no argument to a function
>> that
>> requires a program. A function cannot ultimately protect the caller from
>> his
>> own error.
>>
>> Cheers, W.
>> _______________________________________________
>> talk mailing list
>> talk at lists.nycbug.org
>> http://lists.nycbug.org/mailman/listinfo/talk
>>
>
>
> _______________________________________________
> talk mailing list
> talk at lists.nycbug.org
> http://lists.nycbug.org/mailman/listinfo/talk
>
>
--
regards,
matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nycbug.org/pipermail/talk/attachments/20120229/316ca13a/attachment.html>
More information about the talk
mailing list