bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Bash - Programming

Wed Dec 14, 2011 11:52 am

I don't disagree. I am not 'dissing' shell scripting (EDIT: with bash), just suggesting that other languages are probably better suited (EDIT: to his need), all things considered. The conversation was about programming which, without re-lighting the 'is bash a proper programming language' debate, I view as a little more than piping commands. Sequence & repetition may be pretty much the same in bash. I think though that bash really starts to fall down when you start to consider selection. All those literal expansions to consider, ughh.

Non programmer look for things to program in order to learn, programmers look for ways to avoid programming in order to get to the pub early. As you say glueing the many Linux utilities together with a script is often the most best way to produce a result although that approach may not teach you a lot about the basics of programming.

What I said was that once you have cribbed the few lines to call commands from Python or whatever scripting language then it usually makes sense to keep clear of bash.
For example I recently made a utility to check the results of rsnapshot. It was much easier for me to make this utility using Python where I can use SafeConfigParser or OptionParser or other libraries. I believe this is the point that you are making, use the stuff that has been done before. Python etc has the same access to the shell plus has all its many libraries.
I have tried a number of times with bash, really have, and end up in Python or similar. My experience is that it is just easier.
Also I am not aware of a bash debugger. Thats 33% of programming if you consider programming to be design, code and debug/test. Ok you can echo, its not quite the same though.

So if you can call commands from Python etc then you can start weaving with the many utilities you refer to just as well as with bash plus you have a whole load off libraries as well.

I agree with you though, in programming the best way is to use what has already been done. Don't program if you don't have too, unless for learning or fun.

andywe
Posts: 44
Joined: Thu Dec 01, 2011 5:09 pm
Contact: Website

Re: Bash - Programming

Wed Dec 14, 2011 2:56 pm

Bash does have debugging capabilities ...
Some of the Linux/Unix tools and utilities are built into Bash, others are separate executables ...
From Python you can execute commands be constructing suitable "command line strings" and there are Pythonic variants of many of the Linux/Unix tools and utilities.
If space on the raspberryPi becomes constrained then, as is done with embedded Linux distributions, why not a raspberryPi distribution using Busybox ?
To get the most out of a raspberryPi device suitable Bash scripts will need to be (should be made) available e.g. for stopping and starting services, automating basic system administration ...
Linux is a multiuser, multitasking OS ... how might concepts of multi user and multi tasking be quickly explained or demonstrated other than with Bash ?
What about remote procedure calls and remote file systems - e.g. via NFS ?
What about co-operating with Windows ... SAMBA and all that ?
What about a raspberryPi platform without XWindows ?
[ Just stirring !!! ]

caminati
Posts: 23
Joined: Fri Jul 29, 2011 5:23 pm
Contact: Website

Re: Bash - Programming

Wed Dec 14, 2011 3:01 pm

Quote from andywe on December 14, 2011, 14:56
Bash does have debugging capabilities ...


Agree: a set -x can do wonders.
And, anyway

The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. (B.Kernighan)

I do not think the one above is an overstatement.

dpawson
Posts: 129
Joined: Mon Nov 14, 2011 5:05 pm
Contact: Website

Re: Bash - Programming

Wed Dec 14, 2011 3:28 pm

Quote from andywe on December 13, 2011, 13:41

Any thoughts as to where Bash might fit into a "teaching curriculum" ... ?


Yes. When students have a grasp on what other programming languages can do, are sat back wondering about operating systems, disk maintenance, scripting regular jobs, perhaps daily/monthly, when they are getting bored typing the same thing in at the command prompt time after time.
I.e. when they realise they could be more lazy.

http://tldp.org/LDP/abs/html/
or if you're feeling rich and want/need a ref book.

From Bash to Z shell.

Both work well. Also can be used to provoke an interest in the 1001 mini-tools that are available in Linux.

Bash is the way they make for joined up thinking.

HTH

bradburts
Posts: 341
Joined: Sun Oct 02, 2011 7:07 am

Re: Bash - Programming

Wed Dec 14, 2011 4:40 pm


The most effective debugging tool is still careful thought, coupled with judiciously placed print statements. (B.Kernighan)

I do not think the one above is an overstatement.

Well yes defensive programming is always a good idea.
In the early 80's (your quote is 1979) I would spend a great deal of time considering debugging needs. Flashing a ROM just takes too long. And I was lucky many only had cards, some programed using switches.
These days I am more an advocate for agile development.

I meant debugging via an IDE something which B.Kernighan did not have in 1979.
Perhaps if we were to ask him now he might give a different answer.

As an aside I once shipped an embedded system with judiciously placed debug print statements. The event of interest occured, the prints were made, the I/O blocked, what was a catagory 4 error become catagory 1 as primary system capabilities crawled to a standstill.
I would prefer not to use prints within release builds but then how will I debug them (EDIT: in bash)?
I still include a logging class within my applications and usually have the ability to dynamically control the level of logging (default is off for release builds). I am not sure how I would do this in bash.

As for the earlier post. Again, I am not saying 'no bash'. I am saying 'avoid bash for the purposes of programming and/or learning programming'. Samba etc can all be used within Python, Perl, whatever.
I have already made the point that runparts mainly operates on bash scripts. Adding a service is an important task but can be followed using a simple guide and once learned doesn't really take you that much further forward, other than to an more services to Linux systems.
Not really programming in the design, code test sense.
As for multitasking, I find that subprocess.Popen() works just fine in Python.

Return to “Staffroom, classroom and projects”