LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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


Reply
  Search this Thread
Old 11-18-2009, 01:01 PM   #16
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled

Quote:
Originally Posted by gnashley View Post
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
 
Old 11-18-2009, 01:09 PM   #17
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by smeezekitty View Post
Code:
./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?
Code:
c:~$ type end
bash: type: end: not found
 
Old 11-18-2009, 01:42 PM   #18
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by catkin View Post
Strange. Works for me. What is the "end" statement/command?
Code:
c:~$ type end
bash: type: end: not found
on Damn small linux it says end: command not found
but on ubuntu it wants it on there...strange.
 
Old 11-18-2009, 08:10 PM   #19
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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...
 
Old 11-18-2009, 08:19 PM   #20
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by chrism01 View Post
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...
any way to tell?
 
Old 11-18-2009, 10:26 PM   #21
bartonski
Member
 
Registered: Jul 2006
Location: Louisville, KY
Distribution: Fedora 12, Slackware, Debian, Ubuntu Karmic, FreeBSD 7.1
Posts: 443
Blog Entries: 1

Rep: Reputation: 48
In tcsh:

Code:
% end
end: Not in while/foreach.
Oh, right. C shell derivatives use

Code:
while (expression)
  # stuff here
end

Quote:
Originally Posted by smeezekitty View Post
any way to tell?
Try the following:

Code:
echo $SHELL 
echo $shell 
type bash
alias bash

Last edited by bartonski; 11-18-2009 at 10:48 PM.
 
Old 11-19-2009, 01:16 AM   #22
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
In that case http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/
 
Old 11-19-2009, 02:19 AM   #23
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
here it is
Code:
echo $SHELL
/bin/bash
echo $shell
$SHELL
type bash
bash is /bin/bash
alias bash
alias bash='bash --debug'
 
Old 11-19-2009, 08:59 AM   #24
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by smeezekitty View Post
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.
 
Old 11-19-2009, 11:53 AM   #25
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by theNbomr View Post
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.
 
Old 11-19-2009, 12:30 PM   #26
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
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.
 
Old 11-19-2009, 12:32 PM   #27
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by gilead View Post
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.
 
Old 11-19-2009, 01:41 PM   #28
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Quote:
Originally Posted by smeezekitty View Post
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.

--- rod.
 
Old 11-19-2009, 02:14 PM   #29
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
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...

Edit: Here's an excellent example from this very forum:
http://www.linuxquestions.org/questi...in-awk-770189/

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...

Last edited by gnashley; 11-19-2009 at 02:20 PM.
 
Old 11-19-2009, 03:15 PM   #30
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Original Poster
Rep: Reputation: 231Reputation: 231Reputation: 231
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.
i am using more and more code comments.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM
Bash script can't handle errors when run by cron rosv Programming 4 01-08-2009 07:50 PM
Strange if statement behaviour when using bash/bash script freeindy Programming 7 08-04-2008 06:00 AM
Errors running bash script files bkdc Linux - Newbie 6 02-01-2008 07:44 AM
Bash script. Rsync and MSSQL errors and logging. nattflyger Programming 4 07-19-2006 08:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration