Bash

random by max number of case

$ echo ${RANDOM:0:3}

substitution

  • remove dirname
f="./4-Attya-anatomie/expose.pdf"
echo ${f##*/}
expose.pdf
  • extension
file=ra.pdf
echo "${file:0:-4}"
ra
$ f="/etc/resolv.conf"
$ echo "${f#/etc/}"

resolv.conf
  • not determiner fisrt match
$ f="/etc/resolv.conf"
$ echo "${f#*/}"

resolv.conf

interpreted var : eval it

hello=2020
var="hello"
echo ${!var}
# 2020

format string like a table

  • select words
  • add spaces
  • trim spaces: by accept only 14 char
sed 's/\(\(\w\|+\| \)\{14\}\) */\1'