[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: a quick tip that sometimes saves a lot of further worries




On 10/25/18 9:35 PM, Greg Wooledge wrote:
> On Thu, Oct 25, 2018 at 09:21:27PM +0200, Étienne Mollier wrote:
>> 		for arg in "$@"
>> 		do
>> 			if [ -f "$arg" ]
>> 			then
>> 				printf '<<< %s >>>\n' "$arg"
>> 				cat "./$arg"
> The ./ breaks the function if you give it absolute pathnames.  Replace
> this last line with cat -- "$arg" instead.

Whoopsie!  Indeed.
Got the brain messed with some ./--help file to remove, again...
And since some programs don't (didn't) implement "--", well the
broken solution went first...

> A "clever" version of this part of the function that does something
> similar in a more compact form is:
> 
> tail -n +1 -- "$@"

That's neat!  :-D
It may spew a few errors if for some reason, options are passed to
the editor, and is a little less flexible if we want to add, say
date information, nevertheless cool!

> I didn't write that and can't claim credit for it, but I don't know who
> did, so I can't give appropriate credit either.

I suppose those gentlemen can earn a bit of credit for having
implemented it in "tail" in the first place then, if I trust the
manual:
> AUTHOR
>        Written by Paul Rubin, David MacKenzie, Ian  Lance  Tay‐
>        lor, and Jim Meyering.

Kind Regards,
-- 
Étienne Mollier <etienne.mollier@mailoo.org>


Reply to: