rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* Re: flattening a command substitution
@ 2000-07-11 17:39 Smarasderagd
  0 siblings, 0 replies; 2+ messages in thread
From: Smarasderagd @ 2000-07-11 17:39 UTC (permalink / raw)
  To: fosterd, rc

"Decklin Foster" <fosterd@hartwick.edu> writes:
>Is there a way to perform a command substitution and flatten it all at
>once? For example, say I want to work with a pwd that has spaces:

Or worse, tabs.

>Now, there are two ways I can get it to work: use a newline as the
>ifs-value, or have a temporary variable:
>
>pwd=`{pwd}
>ls $^pwd

I usually do:

nl = '
'

somewhere at the top of the script.  I sometimes also have tab = '	'.
Later, if I want to ignore other whitespace:

ls ``($nl){pwd}

>Neither strike me as being very elegant. The first option doesn't
>generalize to commands with multi-line output, and having to waste a
>variable seems wrong. Does anyone have a better idea?

For commands with multi-line output, ``(){command} seems like the right
thing to me.  As others may have discovered, it still splits the output
if it happens to contain nulls, which I actually find rather useful if
I want to do things with the output of find with the -print0 option...


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

* flattening a command substitution
@ 2000-07-08  2:50 Decklin Foster
  0 siblings, 0 replies; 2+ messages in thread
From: Decklin Foster @ 2000-07-08  2:50 UTC (permalink / raw)
  To: rc

Is there a way to perform a command substitution and flatten it all at
once? For example, say I want to work with a pwd that has spaces:

; pwd
/home/decklin
; mkdir 'foo bar'
; cd 'foo bar'
; ls `{pwd}
ls: /home/decklin/foo: No such file or directory
ls: bar: No such file or directory
[nonzero status 1]
; ls ``(){pwd}
ls: /home/decklin/foo bar
: No such file or directory
[nonzero status 1]
;

Now, there are two ways I can get it to work: use a newline as the
ifs-value, or have a temporary variable:

pwd=`{pwd}
ls $^pwd

Neither strike me as being very elegant. The first option doesn't
generalize to commands with multi-line output, and having to waste a
variable seems wrong. Does anyone have a better idea?

-- 
There is no TRUTH. There is no REALITY. There is no CONSISTENCY. There
are no ABSOLUTE STATEMENTS. I'm very probably wrong. -- BSD fortune(6)


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

end of thread, other threads:[~2000-07-12 22:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-07-11 17:39 flattening a command substitution Smarasderagd
  -- strict thread matches above, loose matches on Subject: below --
2000-07-08  2:50 Decklin Foster

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).