redirect multiple output command linux bash script

maelamrani

New Member
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,
 


JasKinasis

Well-Known Member
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


Latest posts


Top