dt.iki.fi

4 posts are tagged "bash"

Using GNU bash? Forget date!

Since Version 4.2.0 GNU bash can print times in strftime format with printf. OK, the external date command can do a lot that bash's builtin cannot do, but for most use cases this is enough - and it's always better to use builtins, because if you're using bloated bash, at least take full advantage of...

Shell Scripting For Speed

Inspired by a forum thread Make a choice of which shell you use, that's the "#/bin/..." at the top: dash: very small & fast but limited. you will have to use more external commands to accomplish things. bash: bulkier, takes longer to load, maybe slightly slower, but: you can accompl...

Load bash builtin from file

A few years ago I noticed that sleep is not built into bash and instead calls an external command each time. I like to make my scripts responsive and unobtrusive by relying on bash builtins as much as possible; my reasoning: I am using one of the heaviest shells with all its bells and whistles, so a...

Bash: Test if a string is a web link

I sometimes need this in my scripts: if a string starts with either http:// or https://, it must be a web link. How can I test for that in a single query? Like this: $ restore="$(shopt -p extglob)" $ shopt -s extglob $ x="http://wiki.archlinux.org/index.php" $ [[ "$x" == http?(s)://* ]] && e...