Cannot compare argument in if statement in csh/grep command if argument starts with “-“


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot compare argument in if statement in csh/grep command if argument starts with “-“
# 1  
Old 02-17-2011
Cannot compare argument in if statement in csh/grep command if argument starts with “-“

Code:
  If ($argv[1] == “-debug”) then
  Echo “in loop”
  Endif

But this is not working. If I modify this code and remove “-“, then it works.

Similarly I am getting problem using grep command also

Grep “-debug” Filename

Can someone please help me on how to resolve these problems.
# 2  
Old 02-21-2011
Finally i found the soln to my problem.

For prob1, i need to use code like
Code:
If ("$argv[1]" == “-debug”) then
  Echo “in loop”
  Endif

i.e. $argv[1] should be enclosed in double quotes.

For problem while using grep command, is to use it like
Code:
grep '\-debug' filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Python script to grep fields and use values from file 1 as argument for another command

Hi Experts, I am working one one python script in version 3.x and 2.6. Need your support to complete it Basically for both commands i have telnet to device and run command and then receiving input File 1 and File 2 I have two commands, need to grep data and output in csv file. Next script/code... (0 Replies)
Discussion started by: as7951
0 Replies

2. UNIX for Advanced & Expert Users

Error:--test: argument expected--Even though i give an argument.

Hi All, I am running the script VBoxManage list vms |sed 's/"//g' | cut -d " " -f1 > har1out.mytxt result=`cat har1out.mytxt | grep $1' echo $result echo $1 { if then echo pass else echo fail fi (2 Replies)
Discussion started by: harsha85
2 Replies

3. Shell Programming and Scripting

Help on command line argument in csh

HI , I am new to csh. I need to pass some command line arguments like ./abc.sh -os Linux -path abc -tl aa -PILX 1 I have defined the loop as shown below. But its taking "-os" switches as arguments. Its treating them as arguments. How to resolve it? while ( $#argv != 0 ) switch ($argv) ... (7 Replies)
Discussion started by: vineet.dhingra
7 Replies

4. UNIX for Dummies Questions & Answers

grep -v with multiple argument

Hi, I want to grep ORA-XXX errors in a file but not ORA-16055: FAL request rejected ORA-16401: archivelog rejected by RFS ORA-16040: ORA-12154 Then I thought of grep -v ORA-16055 ORA-16401 ORA-16040 ORA-12154 myfile that does not work. Any solution ? (other than : grep -v... (1 Reply)
Discussion started by: big123456
1 Replies

5. Shell Programming and Scripting

csh shell script 'set' argument limit?

Hi , I have a script that is causing a problem that led me to think if there is a limit to the number of arguments for 'set' command in csh shell script. Here is my script: #!/bin/csh -f set top = design_top #1 set v_mbist = ( sim_mbist/*.v ) #2 set v_simlist = ( -v... (2 Replies)
Discussion started by: return_user
2 Replies

6. Shell Programming and Scripting

Recognizing an argument in csh

I will be passing an argument to a csh script The script can be either of two forms For example, either script.csh zloc=5/10 or script.csh zloc=5/10/20 So there can be either two values or three values. How can I distinguish which one the user has inputted? I have made... (1 Reply)
Discussion started by: kristinu
1 Replies

7. Shell Programming and Scripting

Using argument in grep

#!/bin/bash export var=$1 export path=/ank/desktop ll -altr | grep $var > tosend.lst Hi above is the script. but it does not run i gives error regarding usage of grep. Thanks ankur (4 Replies)
Discussion started by: ankurk
4 Replies

8. Shell Programming and Scripting

get positive number n as argument script must calculate the factorial of its argument

Can someone please help me with this SHELL script? I need to create a script that gets a positive number n as an argument. The script must calculate the factorial of its argument. In other words, it must calculate n!=1x2x3x...xn. Note that 0!=1. Here is a start but I have no clue how to... (3 Replies)
Discussion started by: I-1
3 Replies

9. Shell Programming and Scripting

help needed with script that gets a filename as argument (with an if/else statement)

Hi, I am trying to create a script just to study BASH scripting, but I have some problems. I need to create a script that gets a filename as an argument. The script should behave as follows: • If the given file name already exists, inform the user and quit. • If the given file name does... (2 Replies)
Discussion started by: I-1
2 Replies

10. UNIX for Dummies Questions & Answers

How to find the last argument in a argument line?

How to find the last argument in a argument line? (4 Replies)
Discussion started by: nehagupta2008
4 Replies
Login or Register to Ask a Question