I think that's a carriage return issue.
That's the error Bash gives e.g. if the word to the right of a redirection operator expands to multiple fields E.g. as in echo > *
gives bash: *: ambiguous redirect
.
Here, it mentions 1
and there's a line break after. I can get a similar error with an input that has 2>&1<CR><LF>
, e.g.:
$ printf 'echo foo 2>&1\r\n' |bash
: ambiguous redirect
There, the CR moves the cursor to the start of the line, so whatever comes after writes over the first part. Here with the CR visible:
$ printf 'echo foo 2>&1\r\n' |bash 2>&1|cat -A
bash: line 1: 1^M: ambiguous redirect$
I don't know why in your case the CR would be printed as a regular line break, it's probably a terminal setting.
Check if your file came from Windows and run it through dos2unix
or sed -i 's/\r//'
or whatever. A search for "carriage return" should bring some hits.
/bin/sh
? Dies it support backticks? Did you try$()
? – stoney Nov 18 '22 at 15:30date
command should just output a pile of numbers, which shouldn't be problematic for the redirection. – ilkkachu Nov 18 '22 at 16:20