jayy-lmao / bash-meetup

Notes on bash for CODEvelop meetup (WIP)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bash

Basics again

Common commands

  • Structure of a terminal command
  • type
  • piping into grep
  • & = run command in background
  • fg = get program from background and put into forground

Pipes and input/output redirection

echo "In this folder is $(ls)"

Symlinks

ln -s src/file.sh dst/myProgram

Symlinks in bin? Or programs themselves in bin?

Environment variables

You should already have some environment variables which exist. Try echoing them out!

echo $HOME

and

echo $EDITOR

You can also export new variables, or overwrite existing ones.

export EDITOR="vim"

vim basics

  • i = insert mode
  • esc = normal mode
  • arrow keys = move cursor
  • / = search
  • vaw = select a word
  • daw = delete a word

But most importantly...

  • :q = quit
  • :wq = save & quit
  • :!q = quit without saving

Bash functions and Scripting

function yank(){
  xclip -sel clip < $1
}

Math?

echo "$((1 + 2))"

Logic?

AND

mkdir test_folder && cd test_folder

OR

mkdir test_folder || echo "Didnae work!"

Look! we have control flow!

a=2
b=3
if [ a == b ] then
  echo 'a' 
else
  echo 'b'
fi

Using regex!

[[ "2" =~ '[0-9]' ]]

echo most recent exit code

echo $?

Loops

for file in *.md do
  cat $file
done
while true do
 echo "help im stuck"
done
(( i=10 )); while (( i > 0 )) do
  echo "$i bottles of beer on the wall"
  sleep 1
  ((i--))
done
echo th{e,a}n
echo myshow_episode_{0..4}

About

Notes on bash for CODEvelop meetup (WIP)