declare a shell alias in a ruby file

Discussion in 'Ruby' started by jney, Sep 3, 2009.

  1. jney

    jney Guest

    Hello,

    I'm trying to declare a shell alias from a ruby file.

    here is the file test.rb :
    # begin test.rb
    `alias world='echo hello'`
    # end test.rb

    I'm launching it :
    > ruby test.rb


    Then launching the alias :
    > world

    -bash: world: command not found

    Does anyone know how do i declare a shell alias from a ruby file ?
    jney, Sep 3, 2009
    #1
    1. Advertising

  2. Jean-sébastien Jney wrote:
    > Hello,
    >
    > I'm trying to declare a shell alias from a ruby file.
    >
    > here is the file test.rb :
    > # begin test.rb
    > `alias world='echo hello'`
    > # end test.rb
    >
    > I'm launching it :
    >> ruby test.rb

    >
    > Then launching the alias :
    >> world

    > -bash: world: command not found
    >
    > Does anyone know how do i declare a shell alias from a ruby file ?


    You cannot.

    The processes are started as follows:

    your shell --------------> ruby process --------> another shell
    ruby test.rb `xxx`

    Each process is completely independent of the others - with its own
    address space, and its own copy of the ENVironment. When the second
    shell terminates, it cannot affect the ruby process, nor the original
    shell which started that ruby process.

    The only way you can do this is from the original shell itself. Either
    type your alias command at the shell prompt, or put it in a file and do

    . myscript

    The dot (.) means "read this file and execute it as commands within this
    shell"

    You may find the comp.unix.shell FAQ helpful.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, Sep 3, 2009
    #2
    1. Advertising

  3. On 3 sep, 18:16, Brian Candler <> wrote:
    > Jean-sébastien Jney wrote:
    > > Hello,

    >
    > >   I'm trying to declare a shell alias from a ruby file.

    >
    > > here is the file test.rb :
    > > # begin test.rb
    > > `alias world='echo hello'`
    > > # end test.rb

    >
    > > I'm launching it :
    > >> ruby test.rb

    >
    > > Then launching the alias :
    > >> world

    > > -bash: world: command not found

    >
    > > Does anyone know how do i declare a shell alias from a ruby file ?

    >
    > You cannot.
    >
    > The processes are started as follows:
    >
    >    your shell --------------> ruby process --------> another shell
    >                ruby test.rb                 `xxx`
    >
    > Each process is completely independent of the others - with its own
    > address space, and its own copy of the ENVironment. When the second
    > shell terminates, it cannot affect the ruby process, nor the original
    > shell which started that ruby process.
    >
    > The only way you can do this is from the original shell itself. Either
    > type your alias command at the shell prompt, or put it in a file and do
    >
    >   . myscript
    >
    > The dot (.) means "read this file and execute it as commands within this
    > shell"
    >
    > You may find the comp.unix.shell FAQ helpful.
    > --
    > Posted viahttp://www.ruby-forum.com/.


    Thank you both of you.

    eval $(ruby test.rb) works for me.
    But output have to a one line command separate by ";".

    ". myscript" doesn't not work for me. It doesn't read my file as a
    ruby one, althrough my file is starting by "#!/usr/bin/env ruby".

    Thanks.
    Jean-Sébastien, Sep 4, 2009
    #3
    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. Replies:
    2
    Views:
    5,700
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    601
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,078
    Philipp Pagel
    Feb 27, 2008
  4. D'Arcy J.M. Cain
    Replies:
    0
    Views:
    864
    D'Arcy J.M. Cain
    Feb 27, 2008
  5. grocery_stocker
    Replies:
    9
    Views:
    753
    grocery_stocker
    May 24, 2008
Loading...

Share This Page