script with -e command line option???

Discussion in 'Ruby' started by Suresh Unadrad, Jan 26, 2007.

  1. If I type in the following example from "Programming Ruby", I get an
    error:

    $ ruby -n -e "print if /wombat/" *.txt
    -e:1: No such file or directory - if (Errno::ENOENT)

    This is from a BASH command line on a linux system with ruby 1.8.4

    At first I thought it was a problem with BASH interfering with quoting
    or something, but I've tried many variations with no luck. Any idea?

    thanks,

    --su

    --
    Posted via http://www.ruby-forum.com/.
    Suresh Unadrad, Jan 26, 2007
    #1
    1. Advertising

  2. Suresh Unadrad schrieb:
    > If I type in the following example from "Programming Ruby", I get an
    > error:
    >
    > $ ruby -n -e "print if /wombat/" *.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > This is from a BASH command line on a linux system with ruby 1.8.4


    My answer is from Windows 2000, Ruby 1.8.5, but the reason may be, that there is
    no file in your directory which mathes "*.txt"

    >>>>> Example from Windows Console >>>>>


    C:\Dokumente und Einstellungen\wolfgang\Desktop>type otto.txt
    Hello, world!

    I'm here to wombat all thinks,
    whatever wombat means...
    C:\Dokumente und Einstellungen\wolfgang\Desktop>ruby -n -e "print if /wombat/" *.txt
    I'm here to wombat all thinks,
    whatever wombat means...

    >>>>> EoE >>>>>


    Wolfgang Nádasi-Donner
    Wolfgang Nádasi-Donner, Jan 26, 2007
    #2
    1. Advertising

  3. On Jan 26, 2007, at 4:55 PM, Wolfgang N=E1dasi-Donner wrote:

    > Suresh Unadrad schrieb:
    >> If I type in the following example from "Programming Ruby", I get an
    >> error:
    >> $ ruby -n -e "print if /wombat/" *.txt
    >> -e:1: No such file or directory - if (Errno::ENOENT)
    >> This is from a BASH command line on a linux system with ruby 1.8.4

    >
    > My answer is from Windows 2000, Ruby 1.8.5, but the reason may be, =20
    > that there is no file in your directory which mathes "*.txt"
    >
    > >>>>> Example from Windows Console >>>>>

    >
    > C:\Dokumente und Einstellungen\wolfgang\Desktop>type otto.txt
    > Hello, world!
    >
    > I'm here to wombat all thinks,
    > whatever wombat means...
    > C:\Dokumente und Einstellungen\wolfgang\Desktop>ruby -n -e "print =20
    > if /wombat/" *.txt
    > I'm here to wombat all thinks,
    > whatever wombat means...
    >
    > >>>>> EoE >>>>>

    >
    > Wolfgang N=E1dasi-Donner


    I suspect Wolfgang is correct. The output that I get is:

    $ ruby -n -e "print if /wombat/" *.txt
    -e:1: No such file or directory - *.txt (Errno::ENOENT)

    Are you copying the exact message? It's odd that it thinks "if" is =20
    the name. When the file exists it appears to do what you probably =20
    expected.

    $ ls
    README app config doc log script tmp
    Rakefile components db lib public test vendor
    $ ruby -n -e "print if /wombat/" README*
    $ ruby -n -e "print if /Congratulations/" README*
    2. Go to http://localhost:3000/ and get "Congratulations, you've put =20
    Ruby on Rails!"
    3. Follow the guidelines on the "Congratulations, you've put Ruby on =20
    Rails!" screen

    Sorry, I didn't make a new .txt file, but just used what was handy.

    -Rob


    Rob Biedenharn http://agileconsultingllc.com
    Rob Biedenharn, Jan 26, 2007
    #3
  4. Wolfgang Nádasi-donner wrote:
    > My answer is from Windows 2000, Ruby 1.8.5, but the reason may be, that
    > there is
    > no file in your directory which mathes "*.txt"


    no, that's not my problem. oh - but this reminds me that if i just use
    something like "print" for the command line command, then it works fine:

    $ ls *.txt
    test.txt

    $ more test.txt
    I wish I had a fish.
    I wish I had a wombat.
    Fish are tasty.
    Wombats are tasty too.

    $ ruby -n -e "print if /wombat/" *.txt
    -e:1: No such file or directory - if (Errno::ENOENT)

    $ ruby -n -e "print if /wombat/" test.txt
    -e:1: No such file or directory - if (Errno::ENOENT)

    $ ruby -n -e "print" test.txt
    I wish I had a fish.
    I wish I had a wombat.
    Fish are tasty.
    Wombats are tasty too.

    $ ruby -n -e "print" if test.txt
    -e:1: No such file or directory - if (Errno::ENOENT)

    so it seems clear that ruby isn't getting the entire -e argument,
    probably due to intereference by BASH. anyone know how to fix this?

    --su

    --
    Posted via http://www.ruby-forum.com/.
    Suresh Unadrad, Jan 26, 2007
    #4
  5. On Jan 26, 2007, at 5:08 PM, Suresh Unadrad wrote:

    > $ ruby -n -e "print" if test.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > so it seems clear that ruby isn't getting the entire -e argument,
    > probably due to intereference by BASH. anyone know how to fix this?
    >
    > --su


    Well, the first thing to try is changing the kind of quotes.

    $ ruby -n -e 'print if /wombat/' test.txt

    If that doesn't work, I'd start to suspect that you have "ruby"
    defined as an alias or something to make the args be evaluated twice.

    -Rob

    Rob Biedenharn http://agileconsultingllc.com
    Rob Biedenharn, Jan 26, 2007
    #5
  6. On 26.01.2007 23:08, Suresh Unadrad wrote:
    > Wolfgang Nádasi-donner wrote:
    >> My answer is from Windows 2000, Ruby 1.8.5, but the reason may be, that
    >> there is
    >> no file in your directory which mathes "*.txt"

    >
    > no, that's not my problem. oh - but this reminds me that if i just use
    > something like "print" for the command line command, then it works fine:
    >
    > $ ls *.txt
    > test.txt
    >
    > $ more test.txt
    > I wish I had a fish.
    > I wish I had a wombat.
    > Fish are tasty.
    > Wombats are tasty too.
    >
    > $ ruby -n -e "print if /wombat/" *.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > $ ruby -n -e "print if /wombat/" test.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > $ ruby -n -e "print" test.txt
    > I wish I had a fish.
    > I wish I had a wombat.
    > Fish are tasty.
    > Wombats are tasty too.
    >
    > $ ruby -n -e "print" if test.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > so it seems clear that ruby isn't getting the entire -e argument,
    > probably due to intereference by BASH. anyone know how to fix this?


    This looks like "ruby" was a shell script that does not properly quote
    arguments because ruby thinks the first word after "print" is a file
    name. Here you can see the effect:

    robert@fussel ~
    $ ./aa -n -e "print if /wombat/" *.txt
    -e:1: No such file or directory - if (Errno::ENOENT)

    robert@fussel ~
    $ cat aa
    #!/bin/sh -f

    ruby $*


    robert@fussel ~
    $

    Kind regards

    robert
    Robert Klemme, Jan 26, 2007
    #6
  7. Suresh Unadrad

    jab3 Guest

    On Friday 26 January 2007 17:08, Suresh Unadrad <Suresh Unadrad=20
    <>> wrote:
    > Wolfgang N=C3=A1dasi-donner wrote:
    > > My answer is from Windows 2000, Ruby 1.8.5, but the reason may be,
    > > that there is
    > > no file in your directory which mathes "*.txt"

    >
    > no, that's not my problem. oh - but this reminds me that if i just
    > use something like "print" for the command line command, then it
    > works fine:
    >
    > $ ls *.txt
    > test.txt
    >
    > $ more test.txt
    > I wish I had a fish.
    > I wish I had a wombat.
    > Fish are tasty.
    > Wombats are tasty too.
    >
    > $ ruby -n -e "print if /wombat/" *.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > $ ruby -n -e "print if /wombat/" test.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >


    jab3:~% cat > wombat.txt
    I wish I had a fish.
    I wish I had a wombat.
    =46ish are tasty.
    Wombats are tasty too.
    jab3:~% ruby -n -e "print if /wombat/" *.txt
    I wish I had a wombat.
    jab3:~%

    Something is screwy with your setup. Note that it is complaining that=20
    the file 'if' doesn't exist. You could try something like this and see=20
    if it works:

    ruby -n -e "$stdout.print if /wombat/" *.txt

    Why it thinks that 'if' should be a file I'm not sure about.

    =2Djab3

    > $ ruby -n -e "print" test.txt
    > I wish I had a fish.
    > I wish I had a wombat.
    > Fish are tasty.
    > Wombats are tasty too.
    >
    > $ ruby -n -e "print" if test.txt
    > -e:1: No such file or directory - if (Errno::ENOENT)
    >
    > so it seems clear that ruby isn't getting the entire -e argument,
    > probably due to intereference by BASH. anyone know how to fix this?
    >
    > --su
    jab3, Jan 27, 2007
    #7
  8. Robert Klemme wrote:
    >This looks like "ruby" was a shell script that does not properly quote
    >arguments


    Rob Biedenharn wrote:
    > I'd start to suspect that you have "ruby"
    > defined as an alias or something to make the args be evaluated twice.


    Turns out that this was indeed the problem. When I started using the
    ruby fltk extensions, I found that I had to replace /usr/bin/ruby with
    the following script:

    #!/bin/bash

    export LD_ASSUME_KERNEL=2.3.98
    exec /usr/bin/ruby1.8 $*


    so that's why the arguments were being evaluated twice.

    thanks everyone for your help!

    --su

    --
    Posted via http://www.ruby-forum.com/.
    Suresh Unadrad, Jan 27, 2007
    #8
  9. On 27.01.2007 20:13, Suresh Unadrad wrote:
    > Robert Klemme wrote:
    >> This looks like "ruby" was a shell script that does not properly quote
    >> arguments

    >
    > Rob Biedenharn wrote:
    >> I'd start to suspect that you have "ruby"
    >> defined as an alias or something to make the args be evaluated twice.

    >
    > Turns out that this was indeed the problem. When I started using the
    > ruby fltk extensions, I found that I had to replace /usr/bin/ruby with
    > the following script:
    >
    > #!/bin/bash
    >
    > export LD_ASSUME_KERNEL=2.3.98
    > exec /usr/bin/ruby1.8 $*
    >
    >
    > so that's why the arguments were being evaluated twice.
    >
    > thanks everyone for your help!



    You can easily fix that script with this line which will do proper quoting:

    exec /usr/bin/ruby1.8 "$@"

    Kind regards

    robert
    Robert Klemme, Jan 28, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann

    simple question about command line option

    Newsgroup - Ann, Aug 6, 2003, in forum: C++
    Replies:
    2
    Views:
    367
    E. Robert Tisdale
    Aug 6, 2003
  2. SenthilVel
    Replies:
    1
    Views:
    3,500
    dd_fruend
    Aug 4, 2006
  3. Christopher Wood

    PYTHONSTARTUP and the -i command line option

    Christopher Wood, Jun 2, 2005, in forum: Python
    Replies:
    2
    Views:
    2,602
    Simon Percivall
    Jun 3, 2005
  4. Christoph Zwerschke

    Command line option -Q (floor division)

    Christoph Zwerschke, Mar 23, 2006, in forum: Python
    Replies:
    2
    Views:
    291
    Georg Brandl
    Mar 29, 2006
  5. Michele Simionato
    Replies:
    11
    Views:
    451
    vasudevram
    Dec 23, 2006
Loading...

Share This Page