Linux Terminal Glossary
›
Bash Scripting
Bash Scripting
30 commands
#!/usr/bin/env bash
#!/bin/bash
VAR='hello'
echo $VAR
echo "Value is: $VAR"
arr=(one two three)
echo ${arr[1]}
echo ${arr[@]}
echo ${#arr[@]}
for i in ${arr[@]}; do echo $i; done
for i in $(seq 1 10); do echo $i; done
for file in *.txt; do echo $file; done
while read line; do echo $line; done < file.txt
while true; do command; sleep 5; done
if [ condition ]; then ... fi
if [[ $VAR == 'value' ]]; then ... fi
if [[ -f file.txt ]]; then ... fi
if [[ -d dir/ ]]; then ... fi
if [[ -z $VAR ]]; then ... fi
if [[ -n $VAR ]]; then ... fi
if [[ $NUM -gt 10 ]]; then ... fi
case $VAR in val1) cmd1 ;; val2) cmd2 ;; *) default ;; esac
function greet() { echo "Hello, $1"; }
greet Alice
RESULT=$(command)
NUM=$(( 5 + 3 ))
echo $(( 10 % 3 ))
[ -r file ] && echo 'readable'
command || echo 'command failed'
set -euo pipefail
Search all 7,657 commands
instead.