Skip to content

Bash Tips

twang15 edited this page Sep 22, 2021 · 4 revisions

${string%substring} # Deletes shortest match of $substring from back of $string. ${string##substring} # Deletes longest match of $substring from front of $string.

${0%/*} Assuming $0 is a file name, it will give you the directory it is located in. It works the same way as the dirname command.

${0##*/} Assuming $0 is a file name, it will give you the file name without the leading path. It works the same way as the basename command.

pyenv and pipenv

https://gioele.io/pyenv-pipenv#:~:text=More%20precisely%2C%20it%20installs%20packages,environment%2C%20somewhere%20under%20%24PYENV_ROOT%20.

#### run processes and store pids in array
  for i in $n_procs; do
    ./procs[${i}] &
    pids[${i}]=$!
  done

####wait for all pids
  for pid in ${pids[*]}; do
    wait $pid
  done