Errors while using echo

Hi I am new to shell scripting. I am using a shell script to create a SQL script file and then call it as well. The created SQL script file has calls to 2 other sql script file, as well as compile and execute a procedure. all this works fine. I am getting some simple errors. My code is as below

#OBTAINING DATABASE CREDENTIALS
echo -n "Enter the database username: "
read db_user
echo -n "Enter the database password: "
stty -echo
read db_pass
stty echo
echo -n "Enter the database host string: "
read db_host
#OBTAINING THE LOCATION WHERE FILES HAVE BEEN COPIED
echo -n "Enter the location for script files: "
read file_location
#USING THE FILE LOCATION AS INPUT, CREATE THE FILE CONTAINING #THE CALL TO SCRIPTS
echo "spool $file_location/overall_log.log" > newscript.sql
echo "@ $file_location/create_master_table.sql;" >> newscript.sql
echo "@ $file_location/proc1.sql;" >> newscript.sql
echo "begin" >> newscript.sql
echo "proc1();" >> newscript.sql
echo "end;" >> newscript.sql
echo "/" >> newscript.sql
echo "@ $file_location/drop_master_table.sql;" >> newscript.sql
echo "spool off" >> newscript.sql
#EXECUTE THE SCRIPT FILE CREATED. THIS WILL IN TURN CALL OTHER #SCRIPTS,
# COMPILE AND RUN THE PROCEDURE
sqlplus -s ${db_user}/${db_pass}@${db_host} <<EOF
@ $file_location/newnetscript.sql
EOF
exit 0

These are the errros
1.For first few echos: This will display 'Enter the database username' and then the cursor goes to the beginning of the sentence i.e. at 'E'
2. I enter the value(scott/tiger) and then I am getting the error. U can see the overlapping of 'scott' on 'Enter'

scott the database username:
': not a valid identifier4: read: `db_user
'tty: invalid argument `-echo
Try `stty --help' for more information.
tiger
': not a valid identifier7: read: `db_pass
'tty: invalid argument `echo
Try `stty --help' for more information.

....and so on
3. In the later part I am using echo to write to a file named 'netscript.sql'
However the file is created with the name 'netscript.sql?'. Everything else is fine. Only '?' is the problem.

Please help. Also any suggestion for improvement is also appreciated.

Perhaps your script was created on M$ Windows and copied to unix incorrectly?
Can you post the output of this command (it looks for funny characters). In your case there could be lots of carriage-return characters from a M$ text file.

sed -n l myscriptname

-
In a normal unix script the above sed would show just "$" (linefeed) as the line terminator.

you wont be able to use this script in automated jobs, as it needs inputs from user.

how about making this script to take argument on command line, rather than having it interactive ?

I have created this file in notepad. And then FTPed to UNIX. The output of sed -n l shows a lot of return characters. Can u suggest how can I remove these? I mean an editor where I can see this return characters as well.

Use text mode ftp not binary mode ftp. Or transfer the file under a temporary fileaname which ends in ".txt" and rename it afterwards.

Or:
Correct the file at the unix end with program "dos2unix". On some systems this program is called "dos2ux". See the "man" page for your system to be sure.

The recommended editor depends on what unix Operating System you have. They all have "vi" but this can be an acquired taste. I sometimes cut/paste from notepad in to vi (where my connection is through a Windows program emulating a unix terminal).

While I remember, in the filename you post the "?" is probably not a question mark.
Use the "-b" switch to "ls" to find out if there are funny characters in the filename:

ls -lab

FTPing .txt file did not work nor did text mode FTPing. It was retaining the return characters. I am also using an application "Putty". So I also copy pasted into the vi editor and this worked perfect!!!!!

Yes the question mark was not really a question mark but a return character only.

Thanks a lot for replying correctly and that too quickly. The program is working perfect !!!:b:

I have written this program enitrely by going through various posts in this site only. :smiley:

you can convert directly using.. if available

dos2ux <file> or
d2u <file>

Hi Ryan / Methyl
I used dos2unix and got the file converted.
Thanks.

Another way..... if you opened the file with vi to confirm the presence of the '^M' in the file then you can do:

:%!col -b
:x