Add prefix to output #57

Open
opened 2025-01-14 10:43:40 +01:00 by Benjamin_Loison · 1 comment
test.sh:
#!/bin/bash

my_test() {
    sed "s/^/`date`: /"
}

#exec > >(trap "" INT TERM; my_test)
#exec 2> >(trap "" INT TERM; my_test >&2)
echo 'to stdout'
echo 'to stderr' >&2
./test.sh
Output:
to stdout
to stderr
./test.sh
Output:
Tue Jan 14 09:42:38 AM CET 2025: to stdout
Tue Jan 14 09:42:38 AM CET 2025: to stderr

Source: the Unix Stack Exchange answer 440439

<details> <summary><code>test.sh</code>:</summary> ```bash #!/bin/bash my_test() { sed "s/^/`date`: /" } #exec > >(trap "" INT TERM; my_test) #exec 2> >(trap "" INT TERM; my_test >&2) echo 'to stdout' echo 'to stderr' >&2 ``` </details> ```bash ./test.sh ``` <details> <summary>Output:</summary> ``` to stdout to stderr ``` </details> ```bash ./test.sh ``` <details> <summary>Output:</summary> ``` Tue Jan 14 09:42:38 AM CET 2025: to stdout Tue Jan 14 09:42:38 AM CET 2025: to stderr ``` </details> Source: [the Unix Stack Exchange answer 440439](https://unix.stackexchange.com/a/440439)
Author
Owner
Would help [Benjamin_Loison/openssh/issues/38#note_571962](https://salsa.debian.org/Benjamin_Loison/openssh/-/issues/38#note_571962).
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Benjamin_Loison/linux#57
No description provided.