# Errors while using echo

**URL:** <https://community.unix.com/t/errors-while-using-echo/248996>\
**Category:** Shell Programming and Scripting\
**Created:** [September 10, 2009, 8:26am UTC](https://community.unix.com/t/errors-while-using-echo/248996 "2009-09-10T08:26:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![man\_expo](https://community.unix.com/letter_avatar/man_expo/32/6_449c533f586939b6e5f246632a46421f.png) [@man\_expo](https://community.unix.com/u/man_expo)\
**Post date:** [September 10, 2009, 8:26am UTC](https://community.unix.com/t/errors-while-using-echo/248996/1 "2009-09-10T08:26:11Z")

</div>

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

```nohighlight
#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.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_449c533f586939b6e5f246632a46421f.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [September 10, 2009, 8:45am UTC](https://community.unix.com/t/errors-while-using-echo/248996/2 "2009-09-10T08:45:00Z")

</div>

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.

```nohighlight
sed -n l myscriptname

```

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

---

<div class="post-metadata">

**Author:** ![sharadpisal](https://community.unix.com/letter_avatar/sharadpisal/32/6_449c533f586939b6e5f246632a46421f.png) [@sharadpisal](https://community.unix.com/u/sharadpisal)\
**Post date:** [September 10, 2009, 8:48am UTC](https://community.unix.com/t/errors-while-using-echo/248996/3 "2009-09-10T08:48:00Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![man\_expo](https://community.unix.com/letter_avatar/man_expo/32/6_449c533f586939b6e5f246632a46421f.png) [@man\_expo](https://community.unix.com/u/man_expo)\
**Post date:** [September 10, 2009, 8:49am UTC](https://community.unix.com/t/errors-while-using-echo/248996/4 "2009-09-10T08:49:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![methyl](https://community.unix.com/letter_avatar/methyl/32/6_449c533f586939b6e5f246632a46421f.png) [@methyl](https://community.unix.com/u/methyl)\
**Post date:** [September 10, 2009, 8:58am UTC](https://community.unix.com/t/errors-while-using-echo/248996/5 "2009-09-10T08:58:41Z")

</div>

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:

```nohighlight
ls -lab

```

---

<div class="post-metadata">

**Author:** ![man\_expo](https://community.unix.com/letter_avatar/man_expo/32/6_449c533f586939b6e5f246632a46421f.png) [@man\_expo](https://community.unix.com/u/man_expo)\
**Post date:** [September 10, 2009, 11:12pm UTC](https://community.unix.com/t/errors-while-using-echo/248996/6 "2009-09-10T23:12:53Z")

</div>

> [@methyl](#):
>
> Or transfer the file under a temporary fileaname which ends in ".txt" and rename it afterwards.
> 
> 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:
> 
> ```plaintext
> 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. 😃

---

<div class="post-metadata">

**Author:** ![ryandegreat25](https://community.unix.com/letter_avatar/ryandegreat25/32/6_449c533f586939b6e5f246632a46421f.png) [@ryandegreat25](https://community.unix.com/u/ryandegreat25)\
**Post date:** [September 10, 2009, 11:22pm UTC](https://community.unix.com/t/errors-while-using-echo/248996/7 "2009-09-10T23:22:15Z")

</div>

you can convert directly using.. if available

```nohighlight
dos2ux <file> or
d2u <file>

```

---

<div class="post-metadata">

**Author:** ![man\_expo](https://community.unix.com/letter_avatar/man_expo/32/6_449c533f586939b6e5f246632a46421f.png) [@man\_expo](https://community.unix.com/u/man_expo)\
**Post date:** [September 10, 2009, 11:30pm UTC](https://community.unix.com/t/errors-while-using-echo/248996/8 "2009-09-10T23:30:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Vi-Curious](https://community.unix.com/letter_avatar/vi-curious/32/6_449c533f586939b6e5f246632a46421f.png) [@Vi-Curious](https://community.unix.com/u/Vi-Curious)\
**Post date:** [September 10, 2009, 11:45pm UTC](https://community.unix.com/t/errors-while-using-echo/248996/9 "2009-09-10T23:45:05Z")

</div>

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

```nohighlight
:%!col -b
:x

```
