ProgrammingThis 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.
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.
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
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
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
#! /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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.