rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: today's rc programming challenge
@ 1992-04-17 13:23 rsalz
  0 siblings, 0 replies; 4+ messages in thread
From: rsalz @ 1992-04-17 13:23 UTC (permalink / raw)
  To: chupchup, cks; +Cc: rc

I tried your function and got my trailing ` missing.

What's wrong with builtin echo -n ?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: today's rc programming challenge
@ 1992-04-17 12:34 Arnold D. Robbins
  0 siblings, 0 replies; 4+ messages in thread
From: Arnold D. Robbins @ 1992-04-17 12:34 UTC (permalink / raw)
  To: Chris Siebenmann; +Cc: rc

>  Given: a string in a variable.
>  Wanted: the same string but without the newline on the end
> 
>  Challenge: how, in the (possible) presence of any character except binary
> 0 in the string, do to this? Bonus points awarded for the shortest solution,
> the most efficient solution, and one that can be stuck in a function.


	x='foo
	'
	x=`{tr -d '
	' <<< $x}

	fn stripnl { ret=() {
		ret=`{tr -d '
	' <<< $1
		return ret
	}}

Arnold


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: today's rc programming challenge
  1992-04-16 22:11 Chris Siebenmann
@ 1992-04-17 11:07 ` Robert Earl
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Earl @ 1992-04-17 11:07 UTC (permalink / raw)
  To: Chris Siebenmann; +Cc: rc

fn chop {
	l=() {
	for (f in ``$nl{whatis $1}) {
		~ $#l 0 || echo -n $l
		~ $f '''' && {echo ''''; return}
		~ $#l 0 || echo
		l=$f
	}
	}
}

you call it with a variable name rather than the value; and it prints
a variable assignment a la `whatis' on stdout, so to use it:

; foo='testing
	chop.
	'
; eval ``(){chop foo}

and foo is now chopped.  i know the calling syntax is obscure, but
using whatis was convenient - it knows how to quote, and in the
presence of tabs and spaces, echo could get things wrong.

OBChallenge: make this work with more than one argument.  i had to use
"return" to cut out of the loop (which is why it HAS to be in a
function).



^ permalink raw reply	[flat|nested] 4+ messages in thread

* today's rc programming challenge
@ 1992-04-16 22:11 Chris Siebenmann
  1992-04-17 11:07 ` Robert Earl
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Siebenmann @ 1992-04-16 22:11 UTC (permalink / raw)
  To: rc

 Given: a string in a variable.
 Wanted: the same string but without the newline on the end

 Challenge: how, in the (possible) presence of any character except binary
0 in the string, do to this? Bonus points awarded for the shortest solution,
the most efficient solution, and one that can be stuck in a function.

	- cks


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1992-04-17 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-04-17 13:23 today's rc programming challenge rsalz
  -- strict thread matches above, loose matches on Subject: below --
1992-04-17 12:34 Arnold D. Robbins
1992-04-16 22:11 Chris Siebenmann
1992-04-17 11:07 ` Robert Earl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).