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

Re: Bash - Programming

Mon Dec 05, 2011 11:50 am

I am slowly feeling my way round the "forum" etiquette ...
So ... I did a quick search for Bash and failed to find any mention of using Bash to teach programming concepts ...
and, hence, feel that maybe a Bash thread might be appropriate ...
Since the RaspberryPi is based on Linux ... that implies having at least a basic mastery of Linux tools and utilities ...
The Unix philosophy of working with small applications that can be "piped" together has a lot going for it from the point of view of introducing programming.
Knowing Bash and the various Unix tools and utilities "empowers" Linux users. It is even possible to write interactive Bash scripts that can "pop up" little GUI widgets.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23981
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bash - Programming

Mon Dec 05, 2011 12:07 pm

You are right, it's not been mentioned.

I agree a good knowledge of Bash really helps with Linux, but I don't think it's suitable for teaching concepts. Mainly because it's EVIL with the worst syntax in the whole of the civilised world, and quite a lot of the uncivilised bit.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

joe
Posts: 29
Joined: Tue Oct 18, 2011 2:40 pm

Re: Bash - Programming

Mon Dec 05, 2011 12:26 pm

andywe - are you seriously suggesting people write anything other than 'bash scripts' in bash? Crazy talk.

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

Re: Bash - Programming

Mon Dec 05, 2011 12:46 pm

Shell scripting, besides being practical, encourages virtuous laziness, conciseness, parsimony and software leverage.
I find there are didactic values in this: there are fundamentally different ways of thinking involved with respect to coding in a programming language.
Also, you can get very far using only shell scripting, grep, awk and sed, or a subset.
Lately, bash is getting kinda bloated, somehow contradicting the values above, so I would rather turn to (d)ash (busybox's is good), or even rc, which mitigates some idiosyncrasies about quoting, etc...

jussihei
Posts: 1
Joined: Mon Dec 05, 2011 12:28 pm
Contact: Website

Re: Bash - Programming

Mon Dec 05, 2011 1:02 pm

I've had couple of bash scripting sessions with my 7 year old son and he seems to be able to understand the syntax of it.
I think bash is great language for learning basic stream processing (|,<,>) and the concept of input(read) and output(echo/printf).
For us it was a choice between windows cmd.exe and bash and out of these 2 bash was chosen as it has much more easier syntax.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23981
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bash - Programming

Mon Dec 05, 2011 1:39 pm

I'm agreeing that knowing Bash and the concepts is very useful.

I'm also saying that it's no good as a language for teaching programming.

It would be a good subject for teaching shell scripting.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

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

Re: Bash - Programming

Mon Dec 05, 2011 1:48 pm

Thanks for all the replies ...
Interesting comment about writing anything other than bash scripts in bash ...
Think of bash as a "glue language" ... it is possible to incorporate all kinds of things into a Bash script ... e.g. Python scripts, Tcl scripts ...
Conversely it is possible to invoke Bash scripts from within Python, Perl ... or even from within C and C++ programs ...
Of course Linux comes with plenty of useful tools e.g. awk, sed, grep, find ... and when incorporating these into Bash scripts I would argue that Bash is being used as a "glue" language.\
Of course, on small embedded systems there is Busybox ....
Teaching wise (that's what I and FTT do in the main) ... Bash is a great way to learn about what the operating system is doing ... Later on it is possible to teach how the various tools and utilities, and even command line processing tools like Bash might be implemented in C via the Posix API.
For those who wish to "really get under the bonnet" learning about the "mysteries of loadable kernel modules and insmod and all that " will offer another level of understanding.
On Windows (VISTA and above ... ) there is the Powershell ...
Very Bash like, except that it works with the .NET framework ...
I feel a "spiel coming on" so I'll pause ... and let the forum develop this theme ....

Wooloomooloo
Posts: 92
Joined: Fri Nov 25, 2011 10:52 am

Re: Bash - Programming

Mon Dec 05, 2011 2:04 pm

I'm not arguing that bash scripting can be a very powerful and very useful thing. But someone trying to make me learn it would to this day trigger an instant "fight or flight" response from me. Heck, regular expressions are an awesomely useful thing but I hate them with a passion for having to spend a half an hour looking for a syntax reference every single time I need to do a search. Though very far from being an elegant language, the BASIC the micros of yore were running did have the undeniable advantage of a simple syntax, and I think this is key in keeping a novice interested.

In other words, it irks me to no end that even today, even if one knows the basic concepts of programming and has a clearly defined algorithm in mind, one gets invariably bogged down in getting the details of syntax right, surrounded by truckloads of helpful error messages that usually tell you everything except what exactly you did wrong. None of that makes someone trying to learn a language particularly happy. I think having to spend 85% of one's time searching language / API / error code references is really not the way programming should work - yet that's the way it does. Shell scripting even more so.

So yeah, by all means, have it available if someone is interested, but for Pete's sake, don't drive everyone away by trying to teach it to would-be programmers please...

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bash - Programming

Mon Dec 05, 2011 2:19 pm

Quote from Wooloomooloo on December 5, 2011, 14:04
I'm not arguing that bash scripting can be a very powerful and very useful thing. But someone trying to make me learn it would to this day trigger an instant "fight or flight" response from me.
Amen, brother.

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

Re: Bash - Programming

Mon Dec 05, 2011 5:50 pm

http://tldp.org/LDP/abs/html/
If it's not there it likely isn't a part of bash.
The scripting language IMHO... when that creaks, glue in some Python/Ruby.
You only need to be as accurate as the computer you're using dictates.

Dave

User avatar
lobster
Posts: 57
Joined: Sun Sep 11, 2011 6:57 pm
Contact: Website

Re: Bash - Programming

Mon Dec 05, 2011 6:53 pm

Geek kids should be encouraged to learn every language that takes their fancy, even writing their own. Puppy Linux (coming to a Pi near you soon) makes extensive use of customised Bash St kids programming:
http://www.murga-linux.com/pup.....hp?t=40422

misnerspace
Posts: 3
Joined: Fri Dec 02, 2011 12:10 am

Re: Bash - Programming

Tue Dec 06, 2011 6:11 am

Bash is fantastically powerful but I would never introduce it to my students, unless of course they already have programming experience and they have a need for it. Even then I would choose C over bash scripting. In my humble opinion; python for KS4 students and Java for KS5 students with a real focus on OOD. This christmas I am going to 'geek out' on OpenKinect, hopefully there will be a few simple Kinect projects which my high school students might be able to develop at the end of the course. Python can also work with OpenKinect!

anwe79
Posts: 26
Joined: Sat Oct 08, 2011 10:30 pm

Re: Bash - Programming

Wed Dec 07, 2011 12:29 am

Yep, i think this may be a good idea, if only to spark some interest in what you can actually do with a computer (other than web browsing and play games:)). Although i wish there were a better option than bash (i'm not very familiar with the other shells, but i supect they are not that much better).

I've recently started learning bash properly and it's no picnic, but as quick intro to programming it's not bad. Teaching basic programming concepts like conditionals, loops etc, should be easy, and the students wouldn't have to worry about compiling, linking, etc. That kind of stuff can be a bit of a hassle when your starting fresh. With bash, all they'd need is a text editor (well strictly speaking not even that), a reference and some examples and they can start coding straight away.

You'd probably wan't to move on to something less quirky once you get past a certain point though, as not to teach the kids "bad" habits. And also, to teach them that there is no single language that is "best", they are mostly just good at different things.

tumblebomb
Posts: 50
Joined: Sun Nov 27, 2011 4:56 pm

Re: Bash - Programming

Fri Dec 09, 2011 10:35 pm

It sure is quirky..
A piece of Coursework I did once was to create a backup/restore script with BASH. While not particularly simple you can make something useful and teaches a practical skill for kids. making them create things they can use in real world cases is important imo. If they can do Basic then a bit of scripting will be a walk in the park.

User avatar
r3d4
Posts: 968
Joined: Sat Jul 30, 2011 8:21 am
Location: ./

Re: Bash - Programming

Sat Dec 10, 2011 9:38 am

Quote from lobster on December 5, 2011, 18:53
Geek kids should be encouraged to learn every language that takes their fancy, even writing their own.


+1
...
Quote from jamesh on December 5, 2011, 12:07
You are right, it's not been mentioned.

I agree a good knowledge of Bash really helps with Linux, but I don't think it's suitable for teaching concepts. Mainly because it's EVIL with the worst syntax in the whole of the civilised world, and quite a lot of the uncivilised bit.

bash or batch can appear to be unpleasant but i have seen examples of both doing things i find usefully and or interesting

kind of hard to escape them though (no pun intended ;)
Real life is, to most, a long second-best, a perpetual compromise between the ideal and the possible.
-
Meanwhile, the sysadmin who accidentally nuked the data reckons "its best not run anything more with sudo today"
-
what about spike milligan?

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

Re: Bash - Programming

Sat Dec 10, 2011 11:49 am

There are so many languages, whatever takes their fancy is a good start.

I used to consider myself a good programmer, cannot get on with bash at all though. As said bash is just plain EVIL. It is so important to Linux though, all the run-parts xxx.d stuff. Maybe I am just missing that basic concept which allows you into the language.
Usually end up in perl or python which I find nice n easy comming from C, C++, Basic etc world.
Each to their own though.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 23981
Joined: Sat Jul 30, 2011 7:41 pm

Re: Bash - Programming

Sat Dec 10, 2011 12:45 pm

I find it odd that people regard Bash as a programming language. I suppose it is, loosely, but not something for doing projects in. I look on it as scripting, pure and simple. Which I don't regard as programming, but that's just MHO!

I agree you probably need some knowledge of it for using Linux well, but most people can use a Linux system without ever having to use Bash.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
“I think it’s wrong that only one company makes the game Monopoly.” – Steven Wright

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

Re: Bash - Programming

Sat Dec 10, 2011 12:59 pm

Agreed. Good for calling Python scripts but you would not write Pacman in Bash.

There used to be a 'C' obscuration prize.
Most of the examples looked like bash to me.

Just an opinion ;)

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bash - Programming

Mon Dec 12, 2011 8:12 pm

Quote from jamesh on December 10, 2011, 12:45
I find it odd that people regard Bash as a programming language.
It's turing complete. Unpleasant, uncomfortable and unintuitive, but turing complete.

I find myself strangely compelled to rewrite pacman in Bash now. I think I need a drink. Or less drink.

dattaway
Posts: 20
Joined: Tue Nov 15, 2011 11:41 pm

Re: Bash - Programming

Mon Dec 12, 2011 8:36 pm

I always thought bash was clunky, but I'm starting to use it more for everyday things. I feel comfortable getting in the habit, because I know it will be around longer than other proprietary language "studios" that come and go.

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

Re: Bash - Programming

Mon Dec 12, 2011 10:10 pm

[I find myself strangely compelled to rewrite pacman in Bash now. I think I need a drink. Or less drink.

If you write pacman in Bash I will buy you that drink, you will have earned it!

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

Re: Bash - Programming

Tue Dec 13, 2011 1:41 pm

The spectrum of replies is very much as I would expect ...
I agree the Python and Ruby are also very effective "glue" languages and well suited to
teaching as a "first programming language".
I take the view that RaspberryPi as both technology and a community is very much based on embedded Linux, however many abstraction layers we put on top of it.
Command line interpreters are very much a part of modern operating systems ... and for those who
"need to know everything" ... are something that should be known.
It is perfectly possible to teach Bash to beginners with little or no programming experience ( I have done so on numerous intro to Linux courses) ...
I don't think it should be taught to everybody ... only those who need to or simply enjoy being able
to control computers at a relatively low level.
Any thoughts as to where Bash might fit into a "teaching curriculum" ... ?

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Bash - Programming

Tue Dec 13, 2011 6:25 pm

Quote from andywe on December 13, 2011, 13:41
Any thoughts as to where Bash might fit into a "teaching curriculum" ... ?

Honestly? Nowhere, unless bash scripting was specifically required for maintenance of an existing system. I've yet to come across a *n*x based computer where a more suitable scripting language wasn't already available via the standard
#!/bin/INTERPRETER
for every task you might conceivably use bash for, except the occasional hardcoding of command pipelines, which totally bypasses pretty much everything bash is actually capable of.

Really, bash is OK as a shell, but it's bloody awful as an automation tool. It brings nothing to the table in terms of teaching programming, unless you're teaching how *not* to implement a programming language.

I'd rather use JCL. And JCL makes my eyes bleed.

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

Re: Bash - Programming

Tue Dec 13, 2011 8:29 pm

Agreed.
You can & should avoid bash and script in some other language.
Once you have the crib sheet to launch a process or command in Python (or whatever) then why bother with bash?
If you are going to do some serious system admin then some bash will be required of course. Hopefully by then you will have the programming basics and be able to read across.
Bash will allow you to lauch commands a little easier but then everything else if so much harder. You can do so much more in other languages and with far more worked examples.
I have a friend who is a system admin, he is struggling to learn 'normal' languages like Java or Python. He works in a bank and whilst previously systems were hooked together with bash now the push is to use modern scripting languages.
Bash has limited use, be like teaching Forth, it has some uses and users but not many and fewer and fewer, proportionally at least.
Yes you can do things in bash, people have and do. Its just that mostly you would just be far more productive using something else.

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

Re: Bash - Programming

Wed Dec 14, 2011 11:04 am

Quote from bradburts on December 13, 2011, 20:29
Yes you can do things in bash, people have and do. Its just that mostly you would just be far more productive using something else.
That something else is often a handful of utilities adhering to the unix philosophy, and glued together by, uhm... a shell script.
I find that too often people dismissing shell scripting are enamoured with some other spiffy language, and thus overlook the fact that shell scripting has its strengths in pragmatisms like fitting just too well into unix philosophy, the shell executable being around 50k in size (for rc or dash, that is why I insist avoiding the term `bash'), and minimizing the man-time devoted to just getting things done.
So I think that if you talk of productivity, in many cases shell scripting is a winner.
If you want to detract from it, you should look at other aspects, as already done in this thread.
However, one should specify the sort of tasks involved: for example, for computationally-intensive, performance-sensitive computations, sscripting is awkward; on the other hand, for household tasks, having to do with textual data, which I guess are the most common at a global scale, often the coder can get away with few lines of scripting.
It is little sense to express generic assessments without specifying a scenario.

Return to “Staffroom, classroom and projects”