Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
05-23-2006, 01:55 AM
|
#1
|
LQ Newbie
Registered: May 2006
Posts: 18
Rep:
|
compare files in C shell
Hi all,
I want to do compare to files in C shell script but when I try to do it by
if( cmp -s shell.tmp shell) then it starts giving me error that its an if syntax error so I guess cmp is not part of C shell ( same script is working when i wrote it for bash ).
Despite seaching internet a lot I am not able to find out how to compare two file in C shell script .
Any help will be appreciated
|
|
|
05-23-2006, 03:38 AM
|
#2
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,419
|
cmp is an external prog eg man cmp. I suspect you need to be more careful with the C shell syntax; try this page: docs.freebsd.org/44doc/usd/04.csh/paper.pdf or specify bash as the first line eg:
#!/bin/bash
|
|
|
05-23-2006, 04:26 AM
|
#3
|
LQ Newbie
Registered: May 2006
Posts: 18
Original Poster
Rep:
|
Thanx chrism01
Thanx buddy
I am very Thankful to you it was really nice help
|
|
|
05-23-2006, 08:56 AM
|
#4
|
LQ Newbie
Registered: May 2006
Posts: 18
Original Poster
Rep:
|
its not solving my problem
As asked by the chrism01 I have studied that particular document but its still giving me error. so i am still facing some problems.
i am putting complete shell script this shell script is working if I put the #!/bin/bash instead of #!/bin/csh
this file is completely according to as that document specify ... to be more specific if i put the $hello == 0 instead of cmp -s shell shellcopy then it works well
#!/bin/bash
cat make_version_h > shell.tmp
if (cmp -s shell shellcopy) then
echo "Matched file"
else
echo "Not matched file"
fi
any help will be quiet useful to me
I am sorry for my dumbness.actually I am very new to shell scripts
|
|
|
05-23-2006, 11:07 AM
|
#5
|
Member
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424
Rep:
|
How about this?
Code:
cmp -s shell shellcopy
test=$?
if [[ "$test" -eq "0" ]]
then
echo "files are equal"
elif [[ "$test" -eq "1" ]]
then
echo "files differ"
else
echo "something went wrong"
fi
Oh, I just noticed that there's only one thing wrong with your file: try
Code:
if (cmp -s shell shellcopy); then
|
|
|
05-23-2006, 12:01 PM
|
#6
|
LQ Newbie
Registered: May 2006
Posts: 18
Original Poster
Rep:
|
Re
Thanks for your reply
but ur method is working when I put the #!/bin/bash on top of file but if I put #!/bin/csh on file then it says it says
if: Expression Syntax.
I am not getting why this problem is coming .. actually I want to compare two files in C shell.
again thanks for your reply and Informative post
|
|
|
05-23-2006, 03:02 PM
|
#7
|
Member
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424
Rep:
|
OK, so
Code:
#! /usr/bin/csh
cmp -s shell shellcopy
set TEST = $status
if ( "$TEST" == "0" ) then
echo "files are equal"
else if ( "$TEST" == "1" ) then
echo "files differ"
else
echo "something went wrong"
endif
or
Code:
#! /usr/bin/csh
if ( { cmp -s shell shellcopy } ) then
echo "files are equal"
else
echo "nope"
endif
|
|
|
05-23-2006, 10:08 PM
|
#8
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,419
|
Exactly; differnet shells have different syntaxes for certain stuff eg 'if' cmds are a classic example, which is why I ref'd that doc.
If it works when specifying bash shell, why not do it that way? ie Why use C-shell at all, it's pretty old.
|
|
|
05-24-2006, 03:13 AM
|
#9
|
LQ Newbie
Registered: May 2006
Posts: 18
Original Poster
Rep:
|
Thanks every One for very Important help.
|
|
|
All times are GMT -5. The time now is 04:50 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|