Results 1 to 8 of 8

Thread: How to save terminal output?

  1. #1
    Join Date
    Apr 2009
    Location
    Guatemala
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

    Arrow How to save terminal output?

    I would like to save the terminal output to a temporary variable.

    For example, if i execute a command to start lampp I would like to save the contents and show them with notify-send.

    I have read this

    http://www.unix.com/unix-advanced-ex...tput-file.html

    but i have no idea how to save it to a variable and then display it with notify-send command.

  2. #2
    Join Date
    Jun 2008
    Location
    Tennessee
    Beans
    3,421

    Re: How to save terminal output?

    Try:
    Code:
    MYVARIABLE=$(mycommands)
    Note the lack of spaces around the =. This is important.

  3. #3
    Join Date
    Apr 2009
    Location
    Guatemala
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to save terminal output?

    Quote Originally Posted by lykwydchykyn View Post
    Try:
    Code:
    MYVARIABLE=$(mycommands)
    Note the lack of spaces around the =. This is important.

    Entonces,

    myvar=$(sudo lampp start) && notify-send $myvar
    will be ok?

  4. #4
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: How to save terminal output?

    Nothing wrong in using $myvar recursively in your example .
    Give it a try .
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

  5. #5
    Join Date
    Apr 2009
    Location
    Guatemala
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to save terminal output?

    Quote Originally Posted by codemaniac View Post
    Nothing wrong in using $myvar recursively in your example .
    Give it a try .
    works but it's better

    myvar=$(sudo lampp start) && notify-send "$myvar"
    Now, how do i turn it into a bash script?

  6. #6
    Join Date
    Feb 2011
    Location
    Somewhere...
    Beans
    1,554
    Distro
    Ubuntu 14.10 Utopic Unicorn

    Re: How to save terminal output?

    Like this:
    Code:
    #!/bin/bash
    myvar=$(sudo lampp start) && notify-send "$myvar"
    And save it as something.sh. After that, make it executable:
    Code:
    chmod +x something.sh
    You can put it in your ~/bin directory so that you don't have to type /link/to/something.sh, just something.sh

  7. #7
    Join Date
    Apr 2009
    Location
    Guatemala
    Beans
    13
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to save terminal output?

    Quote Originally Posted by zombifier25 View Post
    Like this:
    Code:
    #!/bin/bash
    myvar=$(sudo lampp start) && notify-send "$myvar"
    And save it as something.sh. After that, make it executable:
    Code:
    chmod +x something.sh
    You can put it in your ~/bin directory so that you don't have to type /link/to/something.sh, just something.sh
    What about passing parameters to it? What about having a deffault paramenter of use one provided?

  8. #8
    Join Date
    Jan 2010
    Location
    Sydney, Australia
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: How to save terminal output?

    Quote Originally Posted by chepe263 View Post
    What about passing parameters to it? What about having a deffault paramenter of use one provided?
    You can always pass parameters to your script .
    Something like below .
    Please note that the code is not tested .
    Just trying to give you an idea to get started .
    Code:
    #!/bin/bash
    
    for option in $*
    do
            case $option in
            -m) shift
                myvar=$1
                
                shift
            ;;
            -s) shift
               server=$1
                
                shift
            ;;
            -*) echo "Invalid Option"
            ;;
            esac
    
    done
    
    myvar=$(sudo $server start) && notify-send "$myvar"
    “Progress is made by lazy men looking for easier ways to do things”
    — Robert A. Heinlein

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
  •