Bash
Saturday 14 October 2023

YesNo

1read -p "Do you want to proceed? (y/n) " yn
2
3case $yn in 
4	[yY] ) echo ok, we will proceed;
5		break;;
6	[nN] ) echo exiting...;
7		exit;;
8	* ) echo invalid response;;
9esac

Yes

1read -p "Do you want to proceed? (y/N) " yn
2
3if [[ $yn =~ [yY](es)* ]]
4then
5   echo proceed
6fi

Remove empty lines

1command-here | tr -d '\n'

String checks

1if [ -n "$var" ]; then # if string not empty
2if [ -z "$var" ]; then # if string is empty

For loop

1authors=("author1" "author2" "author3")
2for i in ${authors[@]}
3do
4    echo $i
5done

String start with character

1if [[ $var == c* ]]; then
2  echo "var starts with 'c'";
3fi

Backlinks