Skip to content

Instantly share code, notes, and snippets.

View odadoda's full-sized avatar

Øyvind Dahl odadoda

View GitHub Profile
@odadoda
odadoda / if-100.sh
Created February 28, 2014 12:43
If int equals 100
$NUMBER=100
if [ $NUMBER -eq 100 ] ; then
echo “Number is equal”
fi
@odadoda
odadoda / if-foo.sh
Created February 28, 2014 12:42
If test string
if [ “Foo” == “Foo” ] ; then
echo “Its equal”
fi
@odadoda
odadoda / if-ls.sh
Created February 28, 2014 12:42
If test
if ls ; then
echo “listed all the files”
else
echo “error”
fi
@odadoda
odadoda / if.sh
Last active January 9, 2018 12:43
Bash if
if [ test-commands ]; then
#do something
elif [ more-commands ]; then
#do more something]
else
#do something else
fi
@odadoda
odadoda / bash-array
Last active August 29, 2015 13:56
Bash array operations
# Print the third value in the array
echo ${MY_ARRAY[2]}
# To print everyting in the array:
echo ${MY_ARRAY[@]}
# Get array length
echo ${#MY_ARRAY[@]}
# Add more elements
@odadoda
odadoda / myarray
Last active August 29, 2015 13:56
Array assignment
MY_ARRAY[0]=“Laks”
MY_ARRAY[1]=“Torsk”
MY_ARRAY[2]=“Sild”
MY_ARRAY[3]=“Flyndre”
# or
SECOND_ARRAY=(laks torsk sild "Enda en laks")
@odadoda
odadoda / myvar=expression
Last active August 29, 2015 13:56
Command substitution
MYVAR_1=$(expr 1 + 1)
MYVAR_2=`expr 1 + 1`
# MYVAR_1 and MYVAR_2 are 2
@odadoda
odadoda / myint++
Created February 28, 2014 11:45
Use "expr" to increment a variable
MY_INT=2
MY_INT=`expr $MY_INT + 1`
@odadoda
odadoda / myvar=pewpew
Created February 28, 2014 11:43
Assign variable
MYVAR=“pewpew”;
echo $MYVAR;
@odadoda
odadoda / run-helloworld
Created February 28, 2014 11:42
Run script
./helloworld.sh