This isn't working because the command date
returns a string with spaces in it.
$ date
Wed Oct 16 19:20:51 EDT 2013
If you truly want filenames like that you'll need to wrap that string in quotes.
$ touch "foo.backup.$(date)"
$ ll foo*
-rw-rw-r-- 1 saml saml 0 Oct 16 19:22 foo.backup.Wed Oct 16 19:22:29 EDT 2013
You're probably thinking of a different string to be appended would be my guess though. I usually use something like this:
$ touch "foo.backup.$(date +%F_%R)"
$ ll foo*
-rw-rw-r-- 1 saml saml 0 Oct 16 19:25 foo.backup.2013-10-16_19:25
See the man page for date for more formatting codes around the output for the date & time.
Additional formats
If you want to take full control if you consult the man page you can do things like this:
$ date +"%Y%m%d"
20131016
$ date +"%Y-%m-%d"
2013-10-16
$ date +"%Y%m%d_%H%M%S"
20131016_193655
NOTE: You can use date -I
or date --iso-8601
which will produce identical output to date +"%Y-%m-%d
. This switch also has the ability to take an argument to indicate various time formats:
$ date -I=?
date: invalid argument ‘=?’ for ‘--iso-8601’
Valid arguments are:
- ‘hours’
- ‘minutes’
- ‘date’
- ‘seconds’
- ‘ns’
Try 'date --help' for more information.
Examples:
$ date -Ihours
2019-10-25T01+0000
$ date -Iminutes
2019-10-25T01:21+0000
$ date -Iseconds
2019-10-25T01:21:33+0000
When you tee to multiple process substitutions, you're not guaranteed to get the output in any particular order, so you'd better stick with
paste -t',' <(commanda < file) <(commandb < file)
Assuming cat myfile
stands for some expensive pipeline, I think you'll have to store the output, either in a file or a variable:
output=$( some expensive pipeline )
paste -t',' <(commanda <<< "$output") <(commandb <<< "$output")
Using your example:
output=$( seq 4 )
paste -d' ' <(cat <<<"$output") <(tac <<<"$output") <(awk '$1*=2' <<<"$output")
1 4 2
2 3 4
3 2 6
4 1 8
Another thought: FIFOs, and a single pipeline
mkfifo resulta resultb
seq 4 | tee >(tac > resulta) >(awk '$1*=2' > resultb) | paste -d ' ' - resulta resultb
rm resulta resultb
1 4 2
2 3 4
3 2 6
4 1 8
Best Answer
Use something like this (
bash
):Or alternatively:
if your shell doesn't do the
$(command)
thing.