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.
Ending the script with a ':' is equivalent to having the last line of the script be:
exit 0
Having it at the end of each line will give each line of code an exit status of '0' which is probably not a good thing -I mean if you do error checking after running a line of code, having ':' at the end would destroy whatever exit code the line of code ahd generated.
I was wondering more about it being used after the arguments of another command, which I assume just makes it another argument.
Kevin Barru
./chk.sh chk.sh hello
<Clears screen>
Files do not match
bash: ./chk.sh: line 17: warning no 'end' statement at EOF
./chk.sh chk.sh chk.sh
<Clears screen>
Files match
bash: ./chk.sh: line 17: warning no 'end' statement at EOF
./chk.sh
NO ARGS
Strange. Works for me. What is the "end" statement/command?
I've never heard of 'end' as a cmd statement in bash or ksh. Are you sure the shell is not aliased to something else eg tcsh/csh? Don't know if they use 'end' btw...
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Original Poster
Rep:
Quote:
Originally Posted by chrism01
I've never heard of 'end' as a cmd statement in bash or ksh. Are you sure the shell is not aliased to something else eg tcsh/csh? Don't know if they use 'end' btw...
This works, any suggestions on how to improve it? code looks messy.
Code:
#!/bin/bash
if [[ "$1" = "" || "$2" = "" ]]
then
echo NO ARGS
exit
fi
md5sum $1 > .cksm
md5sum $2 | diff - .cksm > .cksm2
if ["$(more .cksm2)" = ""];
then
clear;echo Files match
else
clear;echo Files do not match
fi
rm .cksm
rm .cksm2
end
A general comment on your coding style is that you could use a lot more indentation. This seems to be the case in all of your posted code. The style used by other posters in this thread demonstrates a generally accepted convention regarding this. Most people find it much more readable that way, and it is the whole reason why this forum provides the [code] tags that cause indentation to be preserved.
--- rod.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Original Poster
Rep:
Quote:
Originally Posted by theNbomr
A general comment on your coding style is that you could use a lot more indentation. This seems to be the case in all of your posted code. The style used by other posters in this thread demonstrates a generally accepted convention regarding this. Most people find it much more readable that way, and it is the whole reason why this forum provides the [code] tags that cause indentation to be preserved.
--- rod.
another reason for the code tags is so its displayed in a fixed font so its actually readable.
using tab and backspace for indentation would really slow down my programming pace.
The couple of extra keystrokes for tabs/spaces might slow down (slightly) your initial typing of the code. But it speeds up your (and our) re-reading and understanding of the code (especially when it comes to understanding the separation of functional areas) so the overall time spent to get the code complete is less.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Original Poster
Rep:
Quote:
Originally Posted by gilead
The couple of extra keystrokes for tabs/spaces might slow down (slightly) your initial typing of the code. But it speeds up your (and our) re-reading and understanding of the code (especially when it comes to understanding the separation of functional areas) so the overall time spent to get the code complete is less.
in my opinion its a pain in the @$$ and slows down both typing and reading.
another reason for the code tags is so its displayed in a fixed font so its actually readable.
using tab and backspace for indentation would really slow down my programming pace.
I find code that is fully left-aligned gains no benefit from fixed-pitch fonts. Since fixed-pitch fonts serve to preserve the alignment of columns, and since the column alignment is most apparent at the left/beginning of each line of visible text, fixed-pitch fonts serve the greatest purpose by aligning whitespace.
With respect to ease of programming and keystroke counts, most modern programmer's editors have built in knowledge of programming styles, and perform most of the alignment work for you. I know, smeeze, you are using MS-DOGS and want to stick with edlin, but this is the 21 century already. If you want others to take the time to read your posted code, you will probably gain a wider audience and faster, more accurate responses by adding some helpful formatting.
You'll probably not get much help if you don't indent your code...
Proper indentation and comments where appropriate are *always* a good idea -no matter how long they take. By the time you finish the script (or tomorrow comes), you'll wish you had done so. Good comments are even more important than the code being right, because they show what you weere thinking, or what you were traing to achieve with the code -and that makes the job easier for you or anyone trying to help you.
When I see code that is completely un-indented, I don't even try to read it as it's like trying to sort out strings of spaghetti without moving them.
Have a long look at the code for any successful project in any language and you'll see thyt they always follow (at least) these two guidelines. Have a look at the code for (nearly) any project that has bugs, produces the wrong output, or won't run, and you'll see the same mess staring back at you like what you posted above...
Quote:
What should the following expression match?
([^[(<]])
....
After being asked to give context, the OP states:
There is no tricks or homework. The only trick here is that It's my fault for I haven't documented my own scripts that has the function...
See, the guy wrote it (or copied it) himself and not even *he* knows what it should do now...
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339
Original Poster
Rep:
I am using just an editor no IDE because really who needs an IDE?
Quote:
Good comments are even more important than the code being right, because they show what you weere thinking, or what you were traing to achieve with the code -and that makes the job easier for you or anyone trying to help you.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.