Test command with special character not work


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Test command with special character not work
# 1  
Old 10-16-2013
Linux Test command with special character not work

Hi all,

Case 1 :
Code:
A=88^M
[ $A -eq 88 ] && echo "PASS"

Result:
Code:
PASS

Case 2:
Code:
A=88
[ $A -eq 88 ] && echo "PASS"

Result:
Code:
PASS

I would like to know why Case 1 and Case 2 got the same result? What make ^M ignored ?

Thanks in advance.

Last edited by Franklin52; 10-16-2013 at 10:34 AM.. Reason: Please use code tags
# 2  
Old 10-16-2013
Enclose them with simple quote and test again
This User Gave Thanks to ctsgnb For This Post:
# 3  
Old 10-16-2013
Thanks the quick reply.

Case 1 :
A=88^M
[ $A -eq '88' ] && echo "PASS"

Result:
PASS

Case 2:
A=88
[ $A -eq '88' ] && echo "PASS"

I have retest with single quote and got the same result.

As I am facing a problem that, the script work in some machine and not work in another, but the script is exactly the same. So, I would like to know any terminal setting will affect the test command when the string comparison with special character.
# 4  
Old 10-16-2013
Other way around.... quotes around the variable, not the number Smilie
# 5  
Old 10-16-2013
Quote:
Originally Posted by sea
Other way around.... quotes around the variable, not the number Smilie
As well as on what is on the right side of the = sign Smilie

Code:
A='88^M'

[ "$A" ...

# 6  
Old 10-16-2013
O ... Thanks ... But it got the Syntax error.

Using "==" rather than -eq will get the difference result. However, I would like to know the reason that what make the -eq comparison ignored special character.

Thanks again.
# 7  
Old 10-16-2013
-eq is a numerical comparison. I get a syntax error for your first case on bash/cygwin, but it may be that your shell implementation is just ignoring any trailing characters which don't evaluate to a number.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed command to add special character (')

I have a file (input) which contains are below. Member Analytics Engine Enterprise Manager Dev Tutorial I want to change contains as below by using sed command 'Member Analytics Engine'; 'Enterprise Manager'; 'Dev Tutorial'; First, I tried to add (') on every first line by using sed... (8 Replies)
Discussion started by: anshu ranjan
8 Replies

2. Shell Programming and Scripting

awk command to find total number of Special character in a column

How to find total number of special character in a column? I am using awk -f "," '$col_number "*$" {print $col_number}' file.csv|wc -l but its not giving correct output. It's giving output as 1 even though i give no special character? Please use code tags next time for your code and... (4 Replies)
Discussion started by: AjitKumar
4 Replies

3. Shell Programming and Scripting

A test command parameter is not valid, when special characters are tried to match

Hi I have a scenario where hyphen(-) from file should be ignored I used the following code if && ; then if ; then pow=$LINE echo $pow > history.txt flag=1 fi fi I get the following output ./valid.sh: -: 0403-012 A test... (7 Replies)
Discussion started by: Priya Amaresh
7 Replies

4. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

5. UNIX for Advanced & Expert Users

special characters in IF TEST

I'm using Korn shell. I'm doing an IF TEST for lots of characters and don't know how to also check for single quote and parentheses and slash. I'm reading a file and some records have garbage characters in them. The following works, but how do I add single quote, parentheses and slash to the IF... (3 Replies)
Discussion started by: sboxtops
3 Replies

6. UNIX for Advanced & Expert Users

awk command in special character

Hi, I want to add below line after end of a file (i.e file1) &&echo "copy done" >> out.txt cat file1 scp user1@server1:/tmp/dir /tmp/dir1 my requirment is cat file1 scp user1@server1:/tmp/dir /tmp/dir1 &&echo "copy done" >> out.txt could any one please help me (7 Replies)
Discussion started by: anshu ranjan
7 Replies

7. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

8. Shell Programming and Scripting

special character

Hi, I am trying to unload file from a database. Which contains few lines with the character below. Rest of the data was unloaded appropriately. a) What does this below character means? b) How can i remove it, I already have sed '/^$/d' c) Will this effect the file by any means... (4 Replies)
Discussion started by: tostay2003
4 Replies

9. Shell Programming and Scripting

Matching a choice of character in test command

Hi ] && exit 0 Although it, the $answer, is 'y', the test operation returns true. && exit 0 This works but I want to do multiple choice matching. I don't want to do like: Please help (2 Replies)
Discussion started by: lalelle
2 Replies

10. Programming

special character ?

hey there im a bit stuck on executing commands that include the special character '?'. can someone recommend a way on how i would be able to execute it?? i thought the glob function could be useful (still mite be) but upon entering the command 'ls pars?' it listed all the files in the... (1 Reply)
Discussion started by: mile1982
1 Replies
Login or Register to Ask a Question