Added option for 'read' not to flush buffer (with '-' as 2nd argument) + now 'launch' removes buffers in /tmp

This commit is contained in:
xdrm-brackets 2018-01-28 16:58:24 +01:00
parent 08f30d2996
commit e84678ac6b
2 changed files with 10 additions and 3 deletions

7
launch
View File

@ -114,8 +114,8 @@ echo -e "#!/bin/bash\nBUF_IN=\"$BUF_IN\"; BUF_OUT=\"$BUF_OUT\";\nIN_PID=$IN_PID;
# (6) Manage ending proccess
#--------------------------------------------------------#
# (1) Kill subproccesses if Ctrl+C #
trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null;" INT;
trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null;" KILL;
trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" INT;
trap "kill -9 $OUT_PID 2>/dev/null; kill -9 $IN_PIT 2>/dev/null; rm $ROOT/config_$1; pkill nc 2>/dev/null; rm $BUF_OUT; rm $BUF_IN; exit 1;" KILL;
# (2) Wait for daemons to stop #
wait $OUT_PID;
@ -125,4 +125,7 @@ pkill nc 2>/dev/null;
# (3) Remove config file #
rm $ROOT/config_$1;
# (4) Remove buffers #
rm $BUF_OUT;
rm $BUF_IN;

6
read
View File

@ -6,6 +6,10 @@ ROOT=$(dirname `realpath $0`);
# (1) Check arguments
test $# -lt 1 && echo "ERR: Missing arguments (name)" && exit 1;
# (2) Manage optional argument #
FLUSH=1;
test $# -ge 2 -a "$2" = "-" && FLUSH=0;
# (2) load configuration file
test -f $ROOT/config_$1 && source $ROOT/config_$1 || ( echo "ERR: No such name" && exit 1 ) || exit 1;
@ -13,4 +17,4 @@ test -f $ROOT/config_$1 && source $ROOT/config_$1 || ( echo "ERR: No such name"
cat $BUF_IN;
# (4) Flush buffer
echo -ne "" > $BUF_IN;
test $FLUSH -eq 1 && echo -ne "" > $BUF_IN;