Errors while using echo


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Errors while using echo
# 1  
Old 09-10-2009
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

Code:
#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.
# 2  
Old 09-10-2009
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.

Code:
sed -n l myscriptname

-
In a normal unix script the above sed would show just "$" (linefeed) as the line terminator.
# 3  
Old 09-10-2009
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 ?
# 4  
Old 09-10-2009
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.

Last edited by man_expo; 09-10-2009 at 09:55 AM..
# 5  
Old 09-10-2009
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:
Code:
ls -lab


Last edited by methyl; 09-10-2009 at 10:04 AM.. Reason: afterthoughts
# 6  
Old 09-11-2009
Quote:
Originally Posted by 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:
Code:
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 !!!Smilie

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

Last edited by man_expo; 09-11-2009 at 12:27 AM..
# 7  
Old 09-11-2009
you can convert directly using.. if available
Code:
dos2ux <file> or
d2u <file>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between echo `ls -l` and echo "`ls -l`" ?

Hi guys, Been messing around with shell programming for a couple of days and I found something that was pretty odd in the behavior of the echo command. Below is an example-: When I type the following in my /home directory from my lxterminal in Debian-: echo "`ls -l`" I get the... (2 Replies)
Discussion started by: sreyan32
2 Replies

2. Shell Programming and Scripting

tcsh - understanding difference between "echo string" and "echo string > /dev/stdout"

I came across and unexpected behavior with redirections in tcsh. I know, csh is not best for redirections, but I'd like to understand what is happening here. I have following script (called out_to_streams.csh): #!/bin/tcsh -f echo Redirected to STDOUT > /dev/stdout echo Redirected to... (2 Replies)
Discussion started by: marcink
2 Replies

3. Shell Programming and Scripting

Errors using ln

ln: Filename1 and Filename2 are identical. Seems to be an error.. Unable to proceed further Can you ppl help me? (5 Replies)
Discussion started by: DevM
5 Replies

4. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

5. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

6. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

7. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

8. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

9. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies

10. Filesystems, Disks and Memory

Help with errors

I am very new to the world of Unix, in the middle of a crash course as I write this due to a system failure for my company. This system went down approximately 24 hours ago due to some apparent thunderstorms that passed through. The problem is that my company, like many others, has laid off... (5 Replies)
Discussion started by: Phaedirean
5 Replies
Login or Register to Ask a Question