redirect multiple output command linux bash script

maelamrani

Member
Joined
Jan 3, 2020
Messages
77
Reaction score
7
Credits
450
Hello,
How to redirect multiple command in a text file by a shell script
i did like this :

#!/bin/sh
exec 5>&1 >> /tmp/file1.txt
echo "-------"
/usr/sbin/lsattr -E -l sys0 -a realmem
echo "-------"
/usr/sbin/lsps -a
exec 1>&5 5>&-

There is a simple way to do it ?
Kind regards,
 


Yes, there is a simpler way.

Enclose the commands in a set of curly braces and then redirect:
Bash:
#!/bin/sh
{
    echo "-------"
    /usr/sbin/lsattr -E -l sys0 -a realmem
    echo "-------"
    /usr/sbin/lsps -a
} >> /tmp/file1.txt
 

Members online


Top