Explore some of the more useful but perhaps more esoteric capabilities of the Bash shell with the blog post Ten More Things I Wish I'd Known About bash. It is a followup to the highly visible post by the same author on Ten Things I Wish I'd Known About bash. Modern shells like Bash, Ksh, and Zsh have over four decades of developent and refinement, making them powerful, flexlble, and fast user interfaces for efficient work — not just excellent scripting languages for automation.
(Score: 2) by turgid on Tuesday January 23 2018, @10:00AM (3 children)
That's a cool one.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 3, Funny) by DannyB on Tuesday January 23 2018, @02:46PM (2 children)
#6: These are very handy for knocking up scripts.
I didin't know scripts could get pregnant.
What doesn't kill me makes me weaker for next time.
(Score: 5, Funny) by Anonymous Coward on Tuesday January 23 2018, @05:25PM (1 child)
Sure they can. How do you think they get child processes?
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @04:16AM
You fork the forkers, that's how.
(Score: 2) by PiMuNu on Tuesday January 23 2018, @10:52AM (21 children)
...ten more things it is easy to do in any modern scripting language; but you never even considered trying in bash (or any shell script).
(Score: 5, Insightful) by turgid on Tuesday January 23 2018, @11:08AM (7 children)
"Gluing things together with a shell script is the Unix way." Gilmour/Waters.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: -1, Offtopic) by Anonymous Coward on Tuesday January 23 2018, @12:04PM
do you know de wey
(Score: 1, Interesting) by Anonymous Coward on Tuesday January 23 2018, @01:46PM (5 children)
I have yet to see any significant software that is the product of unix processes glued together by shell code; it's only been things like configuration scripts or for interactive, "exploratory" programming.
If you wanted to use a scripting language that called out to unix processes that also did real work on its own, you'd have to step up to perl or python.
(Score: 3, Informative) by turgid on Tuesday January 23 2018, @03:24PM
Someone needs to read the Unix Koans of Master Foo.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 3, Funny) by Nerdfest on Tuesday January 23 2018, @04:09PM
15 years ago, the internet would like a word with you. Hell even now, but to a lesser degree.
(Score: 2) by fyngyrz on Tuesday January 23 2018, @10:11PM
All I need to know about whatever command shell is running:
And bingo, now I have one set of scripting knowledge that works with Windows, OSX, and linux. And it's hella powerful.
Ideally, I just set a Python script to be executable and run it directly. Or, if a shell command is the only option because... reasons... then what it does is launch a Python script.
It makes no sense to me to use up brainspace with shell esoterica these days.
(Score: 3, Informative) by urza9814 on Tuesday January 23 2018, @10:58PM
I work for a Fortune 10 company. Our core application has a few hundred shell scripts running every night for batch processing, particularly for data coming in from external sources. Various third party companies SFTP a data file, we validate and do some processing of it with a shell script, then we trigger sql or some other process to load into the database if needed. We do the same thing for data output, and that includes output to numerous state and federal regulatory agencies, so it seems to be a pretty typical way of doing these things. In total we've got around half a million lines of bash/ksh running in production...which I'm sure is nothing compared to our application level Java code, but it's still a hell of a lot more than just "configuration scripts or exploratory programming".
(Score: 2) by http on Thursday January 25 2018, @07:23AM
I have worked at a place where customer managment was (i) written in bash, and (ii) run as CGI. Working there taught me almost as much about bash as lhunath's guide. Maybe not the fastest software, but being a small shop, we never had more than three accounts being created or modified at the same time.
Billing, however, was done in perl. Speed matters in some situations.
I browse at -1 when I have mod points. It's unsettling.
(Score: 3, Informative) by canopic jug on Tuesday January 23 2018, @11:40AM (7 children)
Let me guess, all your sessions default to xonsh [xonsh.org] instead of bash or zsh?
Money is not free speech. Elections should not be auctions.
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @12:46PM (4 children)
I never heard of that. I love the first line of their table, "Sane language" ... bash has no tick
OTOH, I clicked on the xonsh "tutorial" link and got an empty page. Oh dear.
(Score: 2) by tangomargarine on Tuesday January 23 2018, @03:56PM (1 child)
Please tell me "BASHwards-looking" isn't a phrase anybody actually uses. If so, these guys should be slapped for such a crime against the English language.
"Is that really true?" "I just spent the last hour telling you to think for yourself! Didn't you hear anything I said?"
(Score: -1, Redundant) by Anonymous Coward on Tuesday January 23 2018, @08:10PM
https://en.wikipedia.org/wiki/Pun [wikipedia.org]
(Score: 1, Funny) by Anonymous Coward on Tuesday January 23 2018, @05:29PM
See? It's so easy, even an empty tutorial will do. ;-)
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @08:35AM
☐ Sane web development practices
(Score: 1, Interesting) by Anonymous Coward on Tuesday January 23 2018, @08:35PM (1 child)
fish
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @09:13AM
https://fishshell.com/ [fishshell.com]
(Score: 3, Insightful) by Snotnose on Tuesday January 23 2018, @04:36PM (4 children)
I've been using Unix since before most of these scripting languages existed. It always takes me by surprise people don't know this stuff.
When I started you had sh, sed, awk, lexx and yacc for scripting. Tcsh, perl, etc etc etc came much later.
/ that's my lawn you're on
// I put a lot of work into maintaining it
/// Hope you're enjoying it, if you have a picnic I want a piece of fried chicken
When the dust settled America realized it was saved by a porn star.
(Score: 3, Interesting) by bzipitidoo on Wednesday January 24 2018, @12:00AM (2 children)
I started on Apple DOS 3.3 and MSDOS. Apple DOS is amazingly primitive-- doesn't even have a native "copy" command, instead has this utility program they called FID to do various file operations, including copy. MSDOS was much more capable, if not as powerful as bash. But it sure can be a lot easier to use. In bash I frequently do "for i in *.ext; do some_command $i ${i%.*}.foo; done" when I used to do "some_command *.ext" in MSDOS, and it worked, because so often the DOS version of the command was a little smarter about generating an appropriate name for the output file.
Heck, it's only recently that I learned of ${i%.*}. Used to use ${i:0:$((${#i}-4))}, which assumes the extension plus dot is 4 characters.
I've tried and tried to grok bison/yacc and flex/lex, but no luck. Bison hates my grammars, always complains of shift/reduce errors. It was easier to bang out a state machine in C by hand than fool endlessly with those utilities.
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @12:40AM
xargs - learn to use it. xe is nice as well
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @12:42AM
yeech, I'd pipe it through bloody sed first.
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @04:24AM
lex/yacc are lexer/parser generators. What the hell are you doing with it in scripting?
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @01:21PM (15 children)
You have to write software forever and all you have is the unix shells... and the scripts keep getting larger... larger... (no perl, that is a different hell--maybe purgatory)
(Score: 3, Insightful) by DannyB on Tuesday January 23 2018, @02:53PM (12 children)
In hell . . .
* you get Usenet, but there is only one newsgroup: alt.soc.rec.talk.comp.news.sci.misc.
* You only get Windows 3.1
* On an 8 MHz 80386
* The only programming language is Perl
* The only shell is command.com
* The only editor is edlin (that would stop the fighting about vi vs emacs and make people thankful for the hard work that went into both!)
* A whopping 2 GB hard drive!
* For only $7995!
* And 9600 Kbps dialup!
What doesn't kill me makes me weaker for next time.
(Score: 4, Informative) by Freeman on Tuesday January 23 2018, @04:30PM
2GB is too large. 80MB would be much more realistic for the hardware you're talking about. Even then, that would have been top of the line.
Joshua 1:9 "Be strong and of a good courage; be not afraid, neither be thou dismayed: for the Lord thy God is with thee"
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @05:21PM (4 children)
I could deal with all of that except edlin and command.com. I feel my tourrettes acting up again, gotta go.. ;)
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @05:39PM (3 children)
Given that you have Perl, it should be easy to avoid using command.com almost completely.
(Score: 3, Insightful) by turgid on Tuesday January 23 2018, @07:43PM
And I'm sure you could re-implement vi in a dozen lines of Perl.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 2, Funny) by Anonymous Coward on Tuesday January 23 2018, @08:13PM (1 child)
Perl also turns the f$!#%ing tourettes into a programming skill.
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @01:30AM
ROFL - best comment of the day
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @02:33AM (2 children)
That must be with the Turbo button disengaged.
The slowest 386 was 16MHz.
-- OriginalOwner_ [soylentnews.org]
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @09:33AM (1 child)
The first ones were rated at 12 MHz.
(Score: 1) by toddestan on Saturday January 27 2018, @09:15PM
The only reason to go with the 386 is to be able to run Windows 95. Which was sluggish enough on a 486, and had to be complete molasses on a 386. Windows 3.1 ran okay on a 386, and would even run acceptably well on a 286.
Of course, that assumes the luxury of a hard drive. My first PC did not have a hard drive, but it did have 2 floppy drives which was more than what some people had.
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @10:12AM (1 child)
2GBs my word. My 7MHz XT had 21 megs I had reams of games and business applications and three different OS / shell variants and I don't think my hdd utilisation ever reached 25%
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @10:14AM
Also, none of that sounds so bad. Windows 3.1 is a helluva lot better than windows 95 and you gave me perl and an internet connection so I can make that machine do anything that is worth doing. Although on those specs i'd probably just stick with DOS.
(Score: 0) by Anonymous Coward on Wednesday January 24 2018, @09:40PM
You made me feel old. I remember Windows 3.0. I remember editing with debug.com (a DOS command). I don't remember how, but I remember doing it. My first dialup connection from home was over a 1200 baud modem with no AT commands. I had to dial with my phone when establishing a connection--both ways, in the snow.
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @05:37PM
As long as I get to write all the shell scripts myself, and have access to all necessary documentation and enough time for development, I don't see a problem.
Of course, being hell, it will probably be a big heap of existing, badly written scripts to modify, not enough time to even understand one of them, and no accessible documentation for anything.
(Score: 1) by rootsquasher on Tuesday January 23 2018, @06:30PM
So true. I would take bash over perl any day.
(Score: 5, Informative) by Anonymous Coward on Tuesday January 23 2018, @02:21PM
Don't use $RANDOM to create temporary files, as you're not guaranteed to get a unique number. Use the 'mktemp' command instead.
eg.
tmp_file=$(mktemp)
if you need a temporary directory:
tmp_dir=$(mktemp -d)
(Score: 2) by Rich on Tuesday January 23 2018, @03:05PM (5 children)
...starts with the same two letters as "shell". There you have it. That's what shells with their scripting are. UNIX shell acts completely unpredictable to someone who has not used it daily for years. And if someone is made to use it daily for years, it's a waste of development resources that couldn't be matched in late-stage socialist countries.
(Score: 4, Touché) by turgid on Tuesday January 23 2018, @03:25PM (3 children)
This level of ignorance ensures that there will always be gainful employment for those who can give the illusion of working magic.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 3, Insightful) by Rich on Tuesday January 23 2018, @07:21PM (2 children)
The leper in a leper colony will regard leprosy as something perfectly normal. It's not that shell magic is not understandable, just as leprosy is well understood by those with medical knowledge. (Also remember the scene in "Princess Mononoke", where Lady Eboshi employs the lepers as gunsmiths, very useful! ... :P)
Shell is just uneconomical, or at least annoying, to get right, because its expressive basics are fundamentally broken. How often did I come across scripts that broke with spaces in filenames? And it gets especially bad, if the target has to be classical "sh", without "ba", "z", "k" or "da" in front of it.
I, for one, much prefer Python as digital duck tape.
(Score: 4, Insightful) by turgid on Tuesday January 23 2018, @07:40PM
Spaces in file names are an abomination. Anyone who puts spaces in file names is a filthy pervert. The Good Lord gave us the underscore.
It helps to know what language you're writing in when you try to write a program.
Youth, as the great man said, is wasted on the young. Quack.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 3, Insightful) by bob_super on Tuesday January 23 2018, @10:07PM
> How often did I come across scripts that broke with spaces in filenames?
How often did you get STDs from unprotected sex with popular prostitutes?
(Score: 2) by bzipitidoo on Wednesday January 24 2018, @12:16AM
If that was really how the term "shell" was derived, it makes it a portmanteau of "shit" and "hell".
Could be worse. Could have been a bit of oil company propaganda, I mean, imagine if the languages Perl, Python, and PHP were instead named Chevron, Exxon, and BP.
(Score: 1) by negrace on Tuesday January 23 2018, @03:32PM (4 children)
1. Python
2. Python
3. Python
4. Python
5. Python
6. Python
7. Python
8. Python
9. Python
10. Python
(Score: 2) by BsAtHome on Tuesday January 23 2018, @03:50PM
That will get the reply - ten times Hiss, which is what snakes do. Therefore, while we are at the sssss, why not do it properly shhhhh and then more conveniently, bash. Case solved.
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @04:57PM
I have been using Octave for most things beyond trivial bash one-liners. It's way too heavy... but then so is Python :)
(Score: 1, Insightful) by Anonymous Coward on Tuesday January 23 2018, @05:01PM
You put a tab in there somewhere and blew up your smarmy post. Or was it a space? I can't tell because I can't see it. Oh well.
(Score: 2) by turgid on Wednesday January 24 2018, @10:50AM
I thought you were going to say C++ there for a minute.
I refuse to engage in a battle of wits with an unarmed opponent [wikipedia.org].
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @03:45PM
I was going to do something fancy to fix a bunch of photos that had the same name. Then I just moved everything into iCloud and paid the fee.
(Score: 4, Informative) by mmh on Tuesday January 23 2018, @04:42PM (2 children)
Author put in an extra, uneeded, caret. You only need two:
And, imho, I think the author missed two of the best shortcuts in bash:
1: ctrl+r = reverse history search, press ctrl+r, type any part of a previously run command. press ctrl+r to keep going back through the history.
2: alt+. = copy and paste the last argument from the last command. e.g.:
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @08:46PM (1 child)
$ mkdir test
$ cd !$
(Score: 1) by mmh on Tuesday January 23 2018, @09:15PM
alt+. is 2 keys, !$ is 4. It's like golf man.
(Score: 0) by Anonymous Coward on Tuesday January 23 2018, @05:18PM
What nix programmer doesn't know these or the awfully prosaic original 10?
(Score: 4, Interesting) by darkfeline on Tuesday January 23 2018, @06:53PM (3 children)
Another way of saying "I didn't read the manual and didn't realize all of these useful features exist, and I'm proud of my ignorance!" Go read the Bash manual, it's not that long and contains all of these and more.
Hell, go read the POSIX shell specification, it's even shorter and contains a third of these. If you don't know the POSIX shell spec, you have no business writing a shell script.
Join the SDF Public Access UNIX System today!
(Score: 2) by DannyB on Tuesday January 23 2018, @09:32PM
So it's like . . .
Who knew that health care was complicated?
Or Ten Things I Wish I Knew About Being President.
What doesn't kill me makes me weaker for next time.
(Score: 3, Funny) by bzipitidoo on Wednesday January 24 2018, @12:28AM (1 child)
Do you know how to write syntax files for vim? Why not?? Come on, it's only 10 pages of text to read through in the vim help!
(Score: 2) by darkfeline on Wednesday January 24 2018, @06:39PM
No, because Vim is for losers. I use ed, vi, and emacs where appropriate, and I have read the manuals for each.
Join the SDF Public Access UNIX System today!