Find the answer to your Linux question:
Results 1 to 7 of 7
Hello, I have never made a bash script in my life, so i need some help. I want a script thats taking the output of an command and use it ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    7

    Get output of a command

    Hello,

    I have never made a bash script in my life, so i need some help.

    I want a script thats taking the output of an command and use it in a other command.

    somthing like:

    $command1 = 'uptime'

    $command2 = 'customcommand'

    and then the it will be put thogeter and run

    $command2 $command1.

    Do you understand?

  2. #2
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile

    Use pipe command .

    pipe command redirects output command-1 as an input for command-2

    Example:
    Code:
    $ls | more
    output of ls command is the input for more command.

    For more click here
    Pipeline (Unix) - Wikipedia, the free encyclopedia
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  3. #3
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    If you want to take the output of one command and make that the input of another command, and these two commands have been assigned to variables, do this:
    Code:
    command1='uptime'
    command2='customcommand'
    $(command1) | $(command2)
    --
    Bill

    Old age and treachery will overcome youth and skill.

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    7
    Okay, think thats what im after, but the last command must be in "" When its outputted after the first, how do i do that?

  5. #5
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Okay, think thats what im after
    Are you talking about the solution offered by Lakshmipathi, or the one offered by wje_lf?
    the last command must be in "" When its outputted after the first, how do i do that?
    I have no idea what you're asking here. Could you illustrate with an example or something?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  6. #6
    Just Joined!
    Join Date
    May 2008
    Posts
    7
    Your example.


    Okay, im not god to explain but ill try,

    Code:
    command1='uptime'
    command2='customcommand'
    $(command1) | $(command2)
    
    the last output of everything should be:
    
    comstomcommand [options to this command] "uptime"
    
    or
    
    #comstomcommand -s  "22:47:07 up  2:21"

  7. #7
    Just Joined!
    Join Date
    May 2008
    Posts
    7
    I got it working Thanks for the guide lines!


    The code for getting command2 after command1 in qoutes:

    Code:
    command1='uptime'
    command2='customcommand'
    $command2 "`$command1`"

Posting Permissions

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