Discussion:
"Ambiguous redirect" error on a simple shell script
(too old to reply)
Jim Bancroft
2004-05-19 20:58:29 UTC
Permalink
Hi everyone,

When I run the following shell script I get an "ambiguous redirect" error
message; specifically, "ambiguous redirect1", and I can't figure out why.

Here are the contents:

######################
#/bin/bash
echo "hello" >> ./test.log 2>&1
#######################

That's it. Pretty short one.

I'm using RedHat Linux, recent version, maybe a few months old.

Seems the shell doesn't like my "2>&1" for whatever reason, but when I tried
the same script on Solaris I had no problems? If you have any tips I'd be
grateful. Thanks.

-Jim
Chris F.A. Johnson
2004-05-19 23:17:59 UTC
Permalink
Post by Jim Bancroft
Hi everyone,
When I run the following shell script I get an "ambiguous redirect" error
message; specifically, "ambiguous redirect1", and I can't figure out why.
######################
#/bin/bash
echo "hello" >> ./test.log 2>&1
#######################
That's it. Pretty short one.
I'm using RedHat Linux, recent version, maybe a few months old.
Seems the shell doesn't like my "2>&1" for whatever reason, but when I tried
the same script on Solaris I had no problems? If you have any tips I'd be
grateful. Thanks.
Are you calling it from [t]csh?

Fix the shebang:

#!/bin/bash
--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
===================================================================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Stephane CHAZELAS
2004-05-21 13:14:41 UTC
Permalink
Post by Jim Bancroft
Hi everyone,
When I run the following shell script I get an "ambiguous redirect" error
message; specifically, "ambiguous redirect1", and I can't figure out why.
######################
#/bin/bash
echo "hello" >> ./test.log 2>&1
#######################
It may be a DOS type file with CRLF as the line terminator:

Try cat -vt script.sh
You may see:

echo "hello" >> ./test.log 2>&1^M
(^M being CR)

To fix, remove the CRs.
--
Stephane
Joe Beanfish
2004-05-21 17:58:35 UTC
Permalink
Post by Jim Bancroft
Hi everyone,
When I run the following shell script I get an "ambiguous redirect" error
message; specifically, "ambiguous redirect1", and I can't figure out why.
######################
#/bin/bash
echo "hello" >> ./test.log 2>&1
#######################
You meant

#!/bin/bash

Or, if you want it portable

#!/bin/sh

which will work on non-linux varieties as well as linux.

Loading...