MonthNovember 2013

bash variables magic

bashlove

I often find myself searching for a, say, left() or mid() function when coding bash. Somehow my subconscious mind seems to know I’m doing too much in bash and therefore tends to forget things like a simple left() in bash. So I note them here. Lets hope I don’t forget where I wrote that down…

len() in bash

$ var='Hello, World!'
$ echo "${#var}"
13

left() in bash

$ var='Hello, World!'
#${string:position:length}
$ echo "${var:0:5}"
Hello

right() in bash

$ var='Hello, World!'
#${string:position:length}
$ echo "${var:7:${#var}}"
World!
#or a litte more dynamic.. (the 6 most right chars)
echo "${var:$((${#var}-6)):${#var}}"
World!

mid() in bash

$ var='Hello, World!'
#${string:position:length}
$ echo "${var:4:4}"
o, W

string replace first in bash (substitute)

$ var='Hello, World!'
#${string/substring/replacement}
$ echo "${var/o/a}"
Hella, World!

string replace all in bash (substitute)

$ var='Hello, World!'
#${string//substring/replacement}
$ echo "${var//o/a}"
Hella, Warld!

Did I miss one?

week planner sheets

week planner

This is some off line stuff for once: I created a set of sheets to plan my week. I figured this may be useful for others as well, so here are the downloads:

weekplan business English

Wochenplan Geschäftlich Deutsch

weekplan private English

Wochenplan Privat Deutsch

If you have any suggestion to make them more useful to you, please let me know!

© 2017 netmess

Theme by Anders NorenUp ↑