4 ms·
Well for example, I just skimmed through it and I don't see an explanation of quoting, probably one of the first things I would want to explain, around the time
by js2 12y ago
Well for example, I just skimmed through it and I don't see an explanation of quoting, probably one of the first things I would want to explain, around the time variables are explained. It also has examples like this:
#!/bin/bash
for i in $( ls ); do
echo item: $i
done
which both uselessly calls ls (you may as well just use a glob) and doesn't work as intended if there are filenames with spaces in the directory.
You also have:
#!/bin/bash
for i in `seq 1 10`;
do
echo $i
done
Why is it using backticks here instead of $() as in thr former example? Also, no mention that seq is not available on some systems. And, you should be using bash's sequence expression[1] anyway (added in bash 4.x), so the guide is likely out of date.
1. http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion http://www.gnu.org/software/bash/manual/bashref.html#Brace-E...
- chalst 12y agoI use some systems without seq, and they have Bash with version 2.x or 3.x on them (eg., OSX). seq has the nice property that writing a shell or executable replacement is easy. I think the 2nd example is fine. It might be cut and pasted from a POSIX example.
- js2 12y agoThose are fair points. Another nit I just noticed in the second example is the extraneous semicolon.
- dspillett 12y agoUsing ls instead of a glob can be valid if you need to force ordering for some reason (you want to process things in date order for instance, IIRC the order out of a glob wildcard is alphanumeric in most places and arbitrary in some). Your point about spaces in filenames is definitely valid though but my preferred solution to that would be to stab people with a needle every time they put a space in a filename!
- icebraining 12y agoBah, spaces are perfectly cromulent characters. It's the bourne shell that's broken. rc works fine with them.
- dspillett 12y agoThere are a great many things on the command line (less elsewhere, but still some) that don't handle spaces in filenames well. You are probably right that this is a technological fault rather than a problem with spaces themselves, but IMnsHO until we are not regularly using spaces as list item separators using them with the items being listed is asking for issues.
- js2 12y agoYou can easily deal with spaces in bourne shell. Quote your variables. Change the IFS to make it only newlines. Of course, newlines in filenames are perfectly valid too.
- thegeomaster 12y agoSpaces are perfectly okay in a filename. Not that I use them, but this isn't 1990 anymore.
- dTal 12y ago>you should be using bash's sequence expression anyway I'd love to, but it inexplicably doesn't support variables. You have to hard code the range and step. Pretty much useless for most of my use cases.