Bash [ -z hello ]
duckduckgo.com
duckduckgo.com
> The infamous "Advanced" Bash Scripting Guide should be avoided unless you know how to filter out the junk. It will teach you to write bugs, not scripts. In that light, the BashGuide was written: http://mywiki.wooledge.org/BashGuide
Now, that site is on the second "page" of the search results.
That's the danger behind PageRank. If something false is popular enough, it will replace fact.
Backlinks must come from other reputable (in google's algorithm's eye's) sites before they carry any weight.
So, this would mean, tldp.org has a lot of top-ranked linux/bash and related sites pointing to it's pages.
#!/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-E...
I think the 2nd example is fine. It might be cut and pasted from a POSIX example.
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.
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.
At this stage it's no better than a meme: https://groups.google.com/d/msg/comp.os.linux.misc/w0bcKoEye...
I know that if you mention the TLDP stuff in #bash you get yelled at, though.
It'd be nice to see option descriptions extracted from manpages: searching for "df -h" could then produce:
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)I have a branch somewhere that exposes the results as JSON, which should make it easy to integrate if they were interested.
Admittedly I haven't had a lot of time recently to improve explainshell. But I haven't deserted it; it's just a matter of finding a block of free days to focus on it.
(and as always, patches are welcome ;)
$ type [
[ is a shell builtin
$ [ 1 -gt 0
bash: [: missing `]'
$ whereis [
/bin/[
$ /bin/[ 1 -gt 0
# success $ /usr/bin/[ 1 -gt 0 && echo success
/usr/bin/[: missing `]'
$ /usr/bin/[ 1 -gt 0 ] && echo success
success
(This is from coreutils 8.13-3.5 on Debian GNU/Linux)somecommand
if [ $? -ne 0 ]; then echo "it failed"; fi
the parent commenter presumably wants to see
if ! somecommand; then echo "it failed"; fi
somecommand || echo "it failed"
if it's just one statement. There are some cases where it just looks more natural. For example: start_service || log "already started"One of the best days of my life
bash [ -z $hello ]
...or is that a bashism that I'm not aware of? If so, that's just horrible.
Personally, I prefer to write portable shell scripts. Entering "!posix test" into DuckDuckGo to obtain the man page for "test" yields far more meaningful information for the same problem.
Exactly! It's not the best of examples really, is it?
Like this
https://www.debuggex.com/r/IC3q9sEdkKjhuLWU
And explains it like this
bash $?
is not explained.[0] https://github.com/duckduckgo/zeroclickinfo-goodies/blob/mas...