3

How can I force a re-evaluation of this each time?

cat > $(date '+%H-%M-%S').log

So that when I first output something it gets written to one file, and after a few seconds I make another ouput and it will be saved in a new file.

cat just symbolizes a always running program

Markus
  • 149

1 Answers1

2

I replaced cat with a for loop that emits one line per second:

for ch in {a..e} ; do echo $ch ; sleep 1 ; done | \
while IFS= read -r line ; do printf '%s\n' "$line" >> $(date +%H-%M-%S) ; done

I used >> instead of > if more than one line comes in one second. You might need to add the month + day to not mix output from different days.

choroba
  • 47,233