bash variables magic | netmess
bash variables magic | netmess
Extracted Page: https://www.netmess.org/bash-variables-magic/
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
Additional text has been truncated due to copyright reasons. Things without URLs and private things don't get truncated.