One line handies

L

Lyndon Samson

------=_Part_1461_20829698.1123542978337
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

------=_Part_1461_20829698.1123542978337--
 
A

Ara.T.Howard

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

show your config:

ruby -r yaml -r rbconfig -e'y Config::CONFIG'

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
D

David A. Black

Hi --

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

Not necessarily, but we would use PATH and ":" :)


David
 
B

Bruce Woodward

Hi --
=20
On Tue, 9 Aug 2005, Lyndon Samson wrote:
=20
Ruby is such a sweet language that you can achieve alot with little cod= e

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.
=20
Not necessarily, but we would use PATH and ":" :)
=20
=20
David
=20
--=20
David A. Black
(e-mail address removed)
=20
 
A

Ara.T.Howard

Hi --

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

Not necessarily, but we would use PATH and ":" :)

cross platform sed-ness:

harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'
---
- "."
- "~/bin"
- "~/shared/bin"
- /home/ahoward/bin
- /usr/local/sbin
- /usr/sbin
- /sbin
- /data/bin
- /usr/kerberos/bin
- /usr/local/bin
- /bin
- /usr/bin
- /usr/x11r6/bin
- /dmsp/reference/bin
- /usr/local/java/bin

;-)

btw - this is the first use i've ever found for using the %<space> trick...

-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
A

Ara.T.Howard

Hi --

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

Not necessarily, but we would use PATH and ":" :)

cross platform sed-ness:

harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'

oops

harp:~ > ruby -r yaml -e 'y (ENV[% PATH ] || ENV[% path ]).downcase.split(%r [:;] )'


-a
--
===============================================================================
| email :: ara [dot] t [dot] howard [at] noaa [dot] gov
| phone :: 303.497.6469
| Your life dwells amoung the causes of death
| Like a lamp standing in a strong breeze. --Nagarjuna
===============================================================================
 
D

David A. Black

Hi --

Hi --

On Tue, 9 Aug 2005, Lyndon Samson wrote:

Ruby is such a sweet language that you can achieve alot with little code

I'd like to see what 'one-liners' others have come up with.

here's one I find usefull.

ruby -e 'puts ENV["path"].downcase.split(";").sort'

handy for windows but *nix ppl would probably use sed.

Not necessarily, but we would use PATH and ":" :)

cross platform sed-ness:

harp:~ > ruby -r yaml -e 'y ENV[% PATH ].downcase.split(%r [:;] )'

oops

harp:~ > ruby -r yaml -e 'y (ENV[% PATH ] || ENV[% path
]).downcase.split(%r [:;] )'

I'm not sure I get why you'd need all this (YAML, the space trick, the
two cases). Does this:

ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

not work on all platforms? Or are there quote/escaping issues?


David
 
B

Bill Kelly

From: "David A. Black said:
Does this:

ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

not work on all platforms? Or are there quote/escaping issues?

DOS (cmd.exe) will need the double- and single-quotes swapped:

ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"

But... the colon will cause probs, because of windoze paths
like C:\blah\blah ...


Regards,

Bill
 
W

William James

Bill said:
From: "David A. Black said:
Does this:

ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

not work on all platforms? Or are there quote/escaping issues?

DOS (cmd.exe) will need the double- and single-quotes swapped:

ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"

Did you try it without swapping the quotes?

Unlike awk, mawk, and gawk, Ruby under DOS accepts single quotes as
argument wrappers. However, if the string contains |, <, or >, then
you had better use double quotes.
 
B

Bill Kelly

From: "William James said:
Bill said:
DOS (cmd.exe) will need the double- and single-quotes swapped:

ruby -e "puts ENV['PATH'].downcase.split(/[:;]/).sort"

Did you try it without swapping the quotes?

Unlike awk, mawk, and gawk, Ruby under DOS accepts single quotes as
argument wrappers. However, if the string contains |, <, or >, then
you had better use double quotes.

Whoa... ! Thanks. Makes me wonder if that always been true,
even back when the standard Ruby distribution for windows was
cygwin based? Or maybe I got so accustomed to

perl -e 'print "huzzah\n"'
Can't find string terminator "'" anywhere before EOF at -e line 1.

I never tried it on ruby!


Thanks,

Regards,

Bill
 
N

nobuyoshi nakada

Hi,

At Tue, 9 Aug 2005 09:01:45 +0900,
David A. Black wrote in [ruby-talk:151306]:
I'm not sure I get why you'd need all this (YAML, the space trick, the
two cases). Does this:

ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

not work on all platforms? Or are there quote/escaping issues?

No. /home/foo/BIN and /home/foo/bin are different directories
on case-sensitive filesystems.

ruby -e "puts ENV['PATH'].split(File::pATH_SEPARATOR).sort"
 
R

Robert Klemme

J

Josef 'Jupp' SCHUGT

Hi!

At Tue, 9 Aug 2005 09:01:45 +0900,
David A. Black wrote in [ruby-talk:151306]:
ruby -e 'puts ENV["PATH"].downcase.split(/[:;]/).sort'

No. /home/foo/BIN and /home/foo/bin are different directories on
case-sensitive filesystems.

ruby -e "puts ENV['PATH'].split(File::pATH_SEPARATOR).sort"


Follows version that makes PATH case-insensitive. Works even if you
have several environment variables that match /^path$/ (possible under
Linux et. al.) their content is printed one after another).

ruby -e 'ENV.keys.grep(/^path$/i).each { |x| puts ENV[x].split(File::pATH_SEPARATOR)}'

Josef 'Jupp' SCHUGT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top