alias shortcut='command'
(no space surrounding the =)hgrep='history|grep'
exercise:
.bashrc is a file which is executed each time a terminal is created.
exercise
syntax
# use the bashrc
source ${HOOME}/.bashrc
in order to test your modifications, do the following command source ~/.bashrc
syntax:
for var in list items
do
do something
done
to be usefull we need :
var=value
(NO spaces surrounding =)$var
remove '.fa' from all files terminating by 'fa.gde'
for f in `ls il2*.fa.gde`
do
nam=`basename $f .fa.gde`
mv $f $nam.gde
done
sheebang
that describe the interpreter to use, eg: #! /bin/bash
. the sheebang
must be the first line of the script.$0
name of the script$1, $2 ... $n
positional arguments received by the script$#
number of positional arguments received$@
list of argumentsyou will find 2 syntax for the test
[ expression ]
test expression
expression evaluate in true (0) or false (1)
syntax:
var="hello"
[ $var = "hello" ]
echo $?
==> 0 means true
syntax:
var=3
[ $var -eq 2 ]
echo $?
==> 1 means false
syntax:
#! /bin/sh
# check if we got arguments
if [ $# -eq 0 ]
then
echo "no argument provided: exit"
exit 1
fi
# check if file exists
if [ -f $1 ]
then
echo "file $1 exists"
ret=0
else
echo "file $1 does not exists"
ret=1
fi
# exit with significative return value
exit $ret