Results 1 to 5 of 5

Thread: How to make a variable and read from second terminal?

  1. #1
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    How to make a variable and read from second terminal?

    I always wondered about this but never found a way to do it. Say I have two terminals open and I want to save the current path in a variable and read it from the second terminal that I have open. Then in the first terminal I type:

    Code:
    A=$(pwd)
    And in the second I type:

    Code:
    echo $A
    that doesn't work though. I have tryied also with
    Code:
    export A=$(pwd)
    and
    Code:
    alias A=$(pwd)
    but nothing seems to work. Is there a way to do this?

  2. #2
    Join Date
    Apr 2007
    Location
    Behind you
    Beans
    167

    Re: How to make a variable and read from second terminal?

    Variables created in a bash session stay within that session only. Other than saving the value of pwd to a file, the second terminal wont be able to get it.

  3. #3
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    Re: How to make a variable and read from second terminal?

    Quote Originally Posted by piratebill View Post
    Variables created in a bash session stay within that session only. Other than saving the value of pwd to a file, the second terminal wont be able to get it.
    Thanks for your reply. You sir saved me from a headache

  4. #4
    Join Date
    Jul 2009
    Beans
    516
    Distro
    Ubuntu 16.04 Xenial Xerus

    Re: How to make a variable and read from second terminal?

    The only way you could do is if it was a sub process of the parent e.g.

    Start a new terminal then type the following:
    Code:
    $ export MSG="Hello World"
    $ gnome-terminal
    From the newly created terminal type
    Code:
    $ echo $MSG
    Or you can use sockets
    Code:
    $ A=$(nc -l 1234)
    $ echo $A
    Code:
    $ pwd | nc localhost 1234
    but then I'm going way OT....
    Mark your thread as [SOLVED], use Thread Tools on forum page.

  5. #5
    Join Date
    Feb 2010
    Location
    Sweden
    Beans
    227
    Distro
    Ubuntu

    Re: How to make a variable and read from second terminal?

    Quote Originally Posted by btindie View Post
    The only way you could do is if it was a sub process of the parent e.g.

    Start a new terminal then type the following:
    Code:
    $ export MSG="Hello World"
    $ gnome-terminal
    From the newly created terminal type
    Code:
    $ echo $MSG
    Or you can use sockets
    Code:
    $ A=$(nc -l 1234)
    $ echo $A
    Code:
    $ pwd | nc localhost 1234
    but then I'm going way OT....
    Wow! That nc was such a neato thing!! I playied a bit with it and "I'm lovin it"! Finally understood also what the export is all about

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •