Same strings are not equal


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Same strings are not equal
# 1  
Old 08-06-2012
Same strings are not equal

Hi there can anyone help me please. I want to make a program to check if the executable file specified by the user exists in the directory.
When I run this program particulary these lines of code does not work:
Code:
if ("$fi" == "$name") then

where It checks whether the specified file is equal to the file in the directory. I thought it might be due to spaces. However, in both cases there is an additional space. So, I think they should be idetical. And question number 2: I made a brake from the loop in if statement can I do it like that???
Code:
#!/bin/csh
 if ($#argv == 1) then
        set name=$1
        set files=`ls`
        set  numfiles=`echo $files | wc -w`
       @ count=1
        while ( $count < $numfiles)
        set fi=`echo $files | cut -f$count -d ' '`
        if (-f $fi && -x $fi ) then
                        set charnum=`echo $fi | wc -c`
                        if ("$fi" == "$name") then
                                echo "I am here 3"
                                echo $fi
                                break
                        endif
        endif
        @ count = $count + 1
        end
endif

Thanks in advance! :-)
# 2  
Old 08-07-2012
Looks like you are not making friends with your csh problems/questions. Neither could I answer, as my csh days are gone for long.

In bash, however, I would phrase your command like so:
Code:
if [ "$fi" == "$name" ]; then ...

i.e. square brackets with spaces around and a terminating ";". Please be careful not to intermingle your "fi" variable with the fi reserved word to end an if- statement.
This User Gave Thanks to RudiC For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to pass strings from a list of strings from another file and create multiple files?

Hello Everyone , Iam a newbie to shell programming and iam reaching out if anyone can help in this :- I have two files 1) Insert.txt 2) partition_list.txt insert.txt looks like this :- insert into emp1 partition (partition_name) (a1, b2, c4, s6, d8) select a1, b2, c4, (2 Replies)
Discussion started by: nubie2linux
2 Replies

2. Shell Programming and Scripting

If not equal to then loop

How do I go about amending this simple script that prompts for a yes/no response so that if neither Y or N are entered it will loop back back to the original prompt #!/bin/ksh echo "Enter yes of no" read answer if then echo "You selected yes" elif then echo "You selected no" elif... (5 Replies)
Discussion started by: gmears
5 Replies

3. Shell Programming and Scripting

get all the strings after the equal sign

hello just want to ask how you do this? a="b=abc def ghi" c=<all the strings after b=> echo $c output will be abc def ghi thanks!! (1 Reply)
Discussion started by: h0ujun
1 Replies

4. Shell Programming and Scripting

Delete lines in file containing duplicate strings, keeping longer strings

The question is not as simple as the title... I have a file, it looks like this <string name="string1">RZ-LED</string> <string name="string2">2.0</string> <string name="string2">Version 2.0</string> <string name="string3">BP</string> I would like to check for duplicate entries of... (11 Replies)
Discussion started by: raidzero
11 Replies

5. Shell Programming and Scripting

Not equal to in Unix

Guys, I am trying to do below operation LAST_TRANSACTION=2 if ]; then # do something fi If the LAST_TRANSACTION variable is not equal to 1 or 2 or 3 then code inside the if block should be execute. This code is not working, Any help is appreciated. (7 Replies)
Discussion started by: gowrishankar05
7 Replies

6. UNIX for Dummies Questions & Answers

Delete strings in file1 based on the list of strings in file2

Hello guys, should be a very easy questn for you: I need to delete strings in file1 based on the list of strings in file2. like file2: word1_word2_ word3_word5_ word3_word4_ word6_word7_ file1: word1_word2_otherwords..,word3_word5_others... (7 Replies)
Discussion started by: roussine
7 Replies

7. Shell Programming and Scripting

while [ $x -ge 50 ] + and equal to zero ; then

while + and equal to zero ; then what to punt instead of phrase and equal to zero. it's bash thank you in advance (1 Reply)
Discussion started by: losh
1 Replies

8. Shell Programming and Scripting

equal to operator

Hi, I have the below script executed arg="dir" if "$arg" = "dir" then echo "true" else echo "false" fi Please let me know what happens in the if command. My output is: dir: dir: No such file or directory false which is not the desired output. When i used test command... (1 Reply)
Discussion started by: anijan
1 Replies

9. Solaris

Stop+A equal

Hi, I have replaced my current Intel PC machine with Solaris 10, it use to have windows XP. I am sure alot of people already done this and i have seen Solaris running smoothly but having keyboard problem. What is the equal keys in a QWERTY keyboard for selection <Stop+A> ? Is there a... (5 Replies)
Discussion started by: tlee
5 Replies
Login or Register to Ask a Question