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

  • 1
    Code in $(...) is evaluated each time. – choroba Sep 3 '14 at 10:19
  • Doesn't work anyway – Markus Sep 3 '14 at 10:20
  • Maybe you called it in the same second? Try adding -%N at the end. – choroba Sep 3 '14 at 10:21
  • I'm waiting several seconds. And %N made no difference – Markus Sep 3 '14 at 10:22
  • Do you call exactly the same code as shown? – choroba Sep 3 '14 at 10:27

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.