Forum Discussion

thaynes2016_297's avatar
thaynes2016_297
Icon for Nimbostratus rankNimbostratus
Aug 11, 2017

bash assign tmsh output to variable

I have an issue I hope someone has ran accross.

I am attempting to get command output assigned to a variable. which works. But on the console, the command output is returned. I don't want to the output of the tmsh ltm ltm rule command to be displayed on the console, but I want it to be in the variable. of course > /dev/nul doesn't work because the output is suppressed.

its seems that only TMSH commands behave this way. If you look at my $rule you will see I use a command to set it as well.

strip leading space
rule=$(echo $rule | sed -e 's/^[ \t]*//')
OLDIFS=$IFS   
IFS=$'\n'
        getrule="$(tmsh list ltm rule ${rule})"           

poolstocheck=()
for i in ${getrule[@]};  
do :
        if [[ $i == *"pool"* ]]; then
                echo $i
        fi
done

1 Reply

  • Hi Thaynes,

     

    I tried the following code

     

    !/bin/sh
    
    rule="test"
    
    //Same syntax as your script is working
    getrule="$(tmsh list ltm rule ${rule})"
    
    echo $getrule
    
    // different syntax also working
    getrule2=`tmsh list ltm rule ${rule}`
    
    echo $getrule2

    Both syntax are working, so maybe the issue comes from elsewhere

     

    Could you share all you script...

     

    Thanks