Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

line 6: $file: ambiguous redirect

Status
Not open for further replies.

asd1234qwerty

Programmer
Mar 18, 2006
5
GB
Hi, i have the following code, but when i enter the word to add, the following error appears line 6: $file: ambiguous redirect. Does anyone know why?

echo "enter file"
read file
echo "enter word to add"
read word
echo "$word" >> $file

Thanks for your help.
 
i just realized that i needed to add quotation marks to make "$file". But now, it says cannot find file or directory, but it does exist...
 
You shouldn't have to quote [tt]$file[/tt] if you have no spaces or other special characters in the file name you enter.

are you sure this is your whole script? It's complaining about line 6, but I only see 5 lines.

This script works perfectly on my machine.

What value are you entering for "$file"? You could be entering something that creates bad syntax for the last "echo" line.
 
Are you entering a space or wildcard character in your filename? That would cause the last line to get this error.
 
this is all of the code that i am using. when it asks for the file, i simply enter 'text' without the quotations, which is the name of the file which already contains some text in it. Thanks a lot.

echo
echo "file?"
read $file
echo "Enter the new line to add:"
read newline
echo "$newline" >> $file
echo
echo "The new line has been added"
echo "Press any key to continue"
read key
 
Replace this:
read $file
with this:
read file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hmmm ... that's not what was listed in the original post. Kind of tough to help if we're not looking at the code that has the problem.

[banghead]

Oh well, life goes on.

asd1234qwerty, did that solve it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top