unwanted control character in the input


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting unwanted control character in the input
# 1  
Old 10-27-2009
unwanted control character in the input

Hi Shell Scripting Experts,

I have a shell script running daily on a remote machine through ssh. To avoid the trouble of restarting the script when ssh disconnects, I use screen (a unix tool) and run the script within a screen session.

What this script does is to ask the user to input y or n daily and does some file appending based on the input. The following is the script

Code:
echo -n "DO YOU WANT TO APPEND FILE(y/n)? "
read qq

if [ $qq = "y" ]  
then
  echo "appending..."

else
  echo "quitting..." 
fi

However, one strange problem is that occasionally an unwanted character is put before a user's input. The following the full screen output by running sh -x myscript.sh. Notice that the user input a single character y but \020y was the one taken by the session. This problem does not occur always. I don't know whether it has to with the screen tool or something else.

Code:
+ echo -n 'DO YOU WANT TO APPEND FILE(y/n)? ' 
DO YOU WANT TO APPEND PREDS(y/n)? + read qq 
y 
+ '[' $'\020y' = y ']' 
+ echo quitting... 
quitting...

Any suggestions is highly appreciated.

thanks

Jeff

Last edited by Franklin52; 10-27-2009 at 10:29 AM.. Reason: Please use code tags!
# 2  
Old 10-27-2009
Looks like you are picking up a stray control character, probably due to the user.

Code:
if [ $qq == *y ]

Should match ok to either
# 3  
Old 11-01-2009
Hi steadyonabix,

Thanks for your reply. You probably mean
if [[ $qq == *y ]]

It works!

thanks

Jeff
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Removing the ^M control character

I've got a file where each line is separated by ^M characters. I want to be able to cat the file without those lines. When I cat the file now what I see are blank lines. However, the blank lines are actually ^M characters; when I open the file with vi they show up. X38888 No No No... (7 Replies)
Discussion started by: newbie2010
7 Replies

2. Shell Programming and Scripting

Replace Control M (^M) character with new line

Hi All, We are getting an external file in abc.csv format. When opened in excel spread sheet, it is opening alright. But when opened in notepad, I see the contents in a single line. Ftp'd the file in binary mode to AIX UNIX host. When opened, I see Control M (^M) characters in place of New Line... (16 Replies)
Discussion started by: njny
16 Replies

3. Shell Programming and Scripting

overcome unwanted input values in korn shell

Hi All, we are doing automation for installation of oracle, a) ORACLE_HOME_NAME b) ORACLE_HOME above are the argument we need to pass during the script execution, while doing this someone issue the value like ORACLE_HOME=/optware/oracle/11g;rm -rf /optware/oracle/10g its removing... (1 Reply)
Discussion started by: kamauv234
1 Replies

4. Shell Programming and Scripting

control M character in unix file

in a file we are getting control character in a file , is there any way that they can be removed once we have the file for eg. BEGIN-PROCEDURE INITIALIZE ^M LET #row_count = 0^M ^M ^M (2 Replies)
Discussion started by: lalitpct
2 Replies

5. Shell Programming and Scripting

PHP header text/csv unwanted line feed character

We have successfully created a comma delimited file, the results are correct from an sql database query. When using the following headers to print the file using print $data, an extra line feed is added and a blank row appears on the top of the data in Excel: header("Expires: 0"); ... (0 Replies)
Discussion started by: ifimbres
0 Replies

6. UNIX for Dummies Questions & Answers

Odd Control Character issue ^A

Sorry to bug you, but my sed is failing me, I have a file auto generated from abinitio, it has a string of chars ending with a line break, and then it has added a ^A character, I can remove this is vi by using the following %s/^A//g (where ^A is ctrl v and control A), however when I try to sed... (1 Reply)
Discussion started by: badg3r
1 Replies

7. Shell Programming and Scripting

Replace any control character in the string

Need to replace any control character in the string in perl ---------- Post updated at 04:22 PM ---------- Previous update was at 03:50 PM ---------- Any help !!! Thanks in advance (2 Replies)
Discussion started by: hansini
2 Replies

8. UNIX for Dummies Questions & Answers

How to find the ^M(control M) character in unix file?

can any one say about command to find "^M" (Control M)characters in a unix text file. ^M comes when a file ftped from windows to unix without using bin mode. I need the command to find lik this, ex.txt: ------------------------------ ...,name,time^M go^M ...file,end^M... (5 Replies)
Discussion started by: prsam
5 Replies

9. Shell Programming and Scripting

Removing Control M character

Hi, I'm using MKS tool kit to execute KSH on windows and samba to move files to unix from windows. My script is appending header record for the data file. I'm using echo "$header" > $SambaFilename cat $windowsfile >> $SambaFilename But after execution of script ,The file in Unix... (2 Replies)
Discussion started by: ammu
2 Replies

10. UNIX for Dummies Questions & Answers

Control character in a file

Hi All, I am looking for a solution to capture any ASCII control character in a file ( where the ASCII control character is in decimal value from 0 to 31 and 127 ( Hex value from 00 to 1F and 7F ) ) by returning any affected lines. The intended good file should contain "ASCII printable... (5 Replies)
Discussion started by: cursive
5 Replies
Login or Register to Ask a Question