Storing the stdout output of a command in a variable and displaying it is simple: OUTPUT=$(command) echo $OUTPUT If you have longer running commands where you want to display stdout in realtime and also store it in a variable you can tee the output to stderr: OUTPUT=$(command | tee /dev/stderr) OUTPUT=$(command | tee /proc/self/fd/2) OUTPUT=$(command…
Tag: bash
Determine the user who logged on via SSH
Today we had the need to determine the initial id of a user who logged onto a Linux box via SSH and executed the su command. When the su command is issued the effective user is changed and whoami or id commands will report that new user id instead. For anyone who is interested, that…