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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A test command parameter is not valid, when special characters are tried to match
# 1  
Old 05-07-2013
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
Code:
    if [ $LINE != "JAPAN" ] && [ $LINE != "\-" ]; then
        if [ $LINE -ne 1 ]; then
            pow=$LINE
            echo $pow > history.txt
            flag=1
        fi
    fi

I get the following output
Code:
./valid.sh[13]: -: 0403-012 A test command parameter is not valid.

How to use special characters liek "-", "#" in conditional statements of shell
Thanks in advance.. Smilie
# 2  
Old 05-07-2013
There should be no reason to escape -. Perhaps you could try double-quoting $LINE in the test.

I'm not sure the -ne test is a great idea, if you expect $LINE could contain non-numeric data.

What shell are you using (looks like an AIX KSH error number)?
# 3  
Old 05-07-2013
As per my understanding
-ne is used for numerical comparisons and != is used for string comparisons
Am using AIX ksh shell
# 4  
Old 05-07-2013
Assuming "LINE" doesn't equal JAPAN and it doesn't equal - (hyphen), then it must be a number, then it's OK, otherwise not.

I don't have access to AIX now, so I suggest trying this first:
Code:
    if [[ "$LINE" != JAPAN ]] && [[ "$LINE" != "-" ]]; then

Are you trying to match the whole line, or just part of it (i.e. can "JAPAN" appear anywhere on the line, or is that the whole line)?
This User Gave Thanks to Scott For This Post:
# 5  
Old 05-07-2013
It worked as per You suggested.. Basically I thought special characters should be used with a escape sequence(\).. Smilie
# 6  
Old 05-07-2013
Quote:
I thought we should use special characters with a escape sequence(\)
Not always. It depends on the context.
# 7  
Old 05-07-2013
Could You please share in what all contexts escape sequences work and where it doesnt work.. It will be very helpful in the future usage..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep exact match without period or other special characters

If I have a file like the following abc.1 abc abc_1 abc..1 abc*1 abc@1 abc def ghr def...... ddef 5466 def ed def** 123445 I`m trying to find exact words from the list abc def (4 Replies)
Discussion started by: ritakadm
4 Replies

2. Shell Programming and Scripting

awk match shell variable that contains special characters?

How to match a shell variable that contains parenthesis (and other special characters like "!") file.txt contains: Charles Dickens Matthew Lewis (writer) name="Matthew Lewis (writer)"; awk -v na="$name" ' $0 ~ na' file.txt Ideally this would match $name in file.txt (in this... (3 Replies)
Discussion started by: Mid Ocean
3 Replies

3. Shell Programming and Scripting

Test command with special character not work

Hi all, Case 1 : A=88^M && echo "PASS" Result: PASS Case 2: A=88 && echo "PASS" Result: PASS I would like to know why Case 1 and Case 2 got the same result? What make ^M ignored ? Thanks in advance. (6 Replies)
Discussion started by: montor
6 Replies

4. Shell Programming and Scripting

Help with error "por: 0403-012 A test command parameter is not valid."

Hi, im asking for help with the next script: echo ^; then if then printf "\033 query1.sh: export TERM=vt100 export ORACLE_TERM=at386 export ORACLE_HOME=/home_oracle8i/app/oracle/product/8.1.7 export ORACLE_BASE=/home_oracle8i/app/oracle export... (8 Replies)
Discussion started by: blacksteel1988
8 Replies

5. Shell Programming and Scripting

Special characters in parameter

Hello, I'm trying to write a simple (korn) shell script which is called from the command line with some parameters. But one of the parameter contains a "!" sign. For example: myscript.ksh foo bar foo!bar When I call the script like above I always get an error. So I tried to wrap the... (1 Reply)
Discussion started by: merlinhst123
1 Replies

6. Shell Programming and Scripting

if condition error: test: 0403-004 Specify a parameter with this command

Hi all, I would like to ask if there's something wrong with my if - else condition, i couldn't run the script perfectly due to the error in my if - else condition stating that "test: 0403-004 Specify a parameter with this command." below is the snippet of my script if && && ] then echo... (5 Replies)
Discussion started by: jihmantiquilla
5 Replies

7. Shell Programming and Scripting

Special characters in command arguments

Hey Guys, I have a program that populates a database based on input I feed it. so it would look like: cmd arg1 arg2 ... argN Now some of the arguments have special characters in them so I wrote a small script to pull the args and wrap them in quotes ('arg'). The problem is sometimes... (10 Replies)
Discussion started by: aaron0001
10 Replies

8. 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

9. Shell Programming and Scripting

A test command parameter is not valid

Hello, Getting error "A test command parameter is not valid" when trying to run the code below under /sbin/sh AA = "12:00" CHK=$(date +"%H:%M") if then print "Yes" fi Getting 2 errors: 1) "AA: not found" 2) "Specify a parameter with this command" Thanks, IS Please... (5 Replies)
Discussion started by: schureki
5 Replies

10. Shell Programming and Scripting

Help regarding Error message: A test command parameter is not valid

Hi I am getting few messages when trying to run my script from the following lines in the script if test then // SomeCode fi The messages are as follows: testing.sh: OBLIGOR_GROUP_ID: 0403-012 A test command parameter is not valid. testing.sh:... (5 Replies)
Discussion started by: skyineyes
5 Replies
Login or Register to Ask a Question