Files
linux/docs/shells/bash.md

71 lines
985 B
Markdown

# Bash
```bash
#!/bin/bash
script_directory="$(dirname "$(readlink -f "$0")")"
#simbolo para comentário
if <condition>; then
<commands>
fi
if test $variavel -eq 3; then
echo
fi
if [ $variavel -eq 3 ]; then
echo
fi
if [ ! $variavel -eq 3 ]; then
echo
fi
if [ $variavel -eq 3 -a $variavel -eq 2 -o $variavel -eq 1]; then
echo
fi
``
#!/bin/bash
function echoArguments(){
echo "printing ($#) arguments"
for ARGUMENT in "$@"
do
echo $ARGUMENT
done
}
echoArguments $@
Também é possível aceder por índice
#!/bin/bash
function echoArguments(){
echo "$0"
echo "$1"
}
echoArguments $@
Testar se um programa está a correr
if pgrep jivelite>/dev/null
then echo "a correr"
else echo "nao esta correr"
fi
verifica o numero de parametros
cuidado tem que ter mesmo os espaços nos parenteses rectos
if [ "$#" -ne 2 ]
then
echo "wrong number of parameters($#)"
echo "0 - name of processo to search"
echo "1 - commando to start"
exit 1
fi
``