Skip to content

Bash

Basic Coding

# comment

variable1="hola"
variable2=123
variable3="$((2+2))"
variable4=$(($RANDOM % 10))

declare -i numero=123
declare -a array=( 1 2 3 4 5 6 )
declare -r str="read only"
suma='expr $variable2 +1'    # convert to string at number

echo content
echo $(variable,,)  #convert lowercase
echo $(variable^^)  # cpnvert uppercase
echo $((3+3)) 
echo $variable

read hola           # enter text and saved in hola
echo $1             # first value enter
echo $2             # second value enter
echo $@             # work with all values
echo $#             # count the elements that input

cat << parte        # show in console
content
content
content
parte

Conditions

if [ value ]; then
    coding
elif [ value ]; then
    coding
fi
case value in
    help) coding ;;
    show) coding ;;
esac
array=( 1 2 3 4 5 6 )
array[6]=7

echo $(array[@])
echo $(array[1])
echo $(array[*])
echo $(! array[@])  # indice of elements
echo $(# array[@])  # amount of elements
& # usage at end of the la execution of an processs for sent task in paralleled
for item in {content}; do coding done

for (( i=0; i < 100; i+=1))
do
    coding
done

for i in $(seq 1 10)
do 
 echo "$i"
done

for element in $(array[@])
do
    echo $element
done
while [ $variable - condition ]
do
    coding
    coding
    coding
done

functions

function name(){
    variables
    conditions
}

name