Documente Academic
Documente Profesional
Documente Cultură
Introduo
Conceitos Bsicos
Editores
Entrada e Sada
Filtragem de Dados
Editores
Prticas
INTRODUO
INTRODUO
Shells tpicos
Korn shell (ksh)
Bourne shell (sh)
C Shell (csh)
Bourne Again Shell (bash)
Remote Shell (rsh)
Secure Shell for SSL telnet connections (ssh)
HELLO WORLD
HELLO WORLD
#!/bin/bash
# My first script
echo "Hello World!
HELLO WORLD
$ ./meu_script.sh
HELLO WORLD
$ echo $PATH
$ export PATH=$PATH:diretrio
meu_script
VARIVEIS
VARIVEIS
#!/bin/bash
NAME="Criptografia"
echo $NAME
VARIVEIS
Variveis Especiais
$0 - O nome do script atual.
$n - Correspondem aos argumentos de um script, em que n
um nmero natural positivo que corresponde posio do
argumento.
$# - O nmero de argumentos fornecidos a um script.
$* - Todos os argumentos so agrupados. Se um script recebe
dois argumentos $* equivalente a $1 $2.
$@ - Mesmo que o anterior.
$$ - O nmero do processo do shell atual
ARRAYS
ARRAYS
#!/bin/sh
NAME[0]="Zara"
NAME[1]="Qadir"
NAME[2]="Mahnaz"
NAME[3]="Ayan"
NAME[4]="Daisy"
echo Primeiro ndice: ${NAME[0]}"
echo Segundo ndice: ${NAME[1]}"
OPERADORES
OPERADORES ARITMTICOS
+ (Adio) Adds values on either side of the operator `expr $a + $b` will give 30
- (Subtrao) Subtracts right hand operand from left hand operand `expr $a - $b` will give -10
* (Multiplicao) Multiplies values on either side of the operator `expr $a \* $b` will give 200
/ (Diviso) Divides left hand operand by right hand operand `expr $b / $a` will give 2
% (Mdulo) Divides left hand operand by right hand operand and `expr $b % $a` will give 0
returns remainder
== (igualdade) Compares two numbers, if both are same then [ $a == $b ] would return
returns true. false.
!= (desigualdade) Compares two numbers, if both are different then [ $a != $b ] would return true.
returns true.
OPERADORES RELACIONAIS
Operador Descrio (ingls) Exemplo (ingls)
-eq Checks if the value of two operands are equal or not; if [ $a -eq $b ] is not true.
yes, then the condition becomes true.
-lt Checks if the value of left operand is less than the value
of right operand; if yes, then the condition becomes [ $a -lt $b ] is true.
true.
case $NUM in
1) echo "one" ;;
2) echo "two" ;;
3) echo "three" ;;
4) echo "four" ;;
5) echo "five" ;;
*) echo "INVALID NUMBER!" ;;
esac
LAOS
FOR
FOR
#!/bin/bash
for i in {10..0};
do
echo $i
done
FOR
#!/bin/bash
#!/bin/bash
while [ CONDICAO ];
do
AES
done
FOR
#!/bin/bash
echo Informe o que voc quiser, -1 para sair
read dado;
while [ $dado != -1 ];
do
echo Voc digitou $dado
read dado;
done
FOR
#!/bin/bash
echo Informe at que valor positivo e maior que zero contar:
read valor;
i=1
while [ $i -le $valor ];
do
echo $i
((i=$i+1))
done
FUNES
FUNES
nome_funcao()
{
AES
}
FUNES
#!/bin/sh
Hello () {
echo "Hello World $1 $2"
return 10
}
Hello Zara Ali
# Capture value returnd by last command
ret=$?
echo "Return value is $ret"
EDITORES
EDITORES
nano
vim
atom
PRTICAS
QUEBRA DE SENHA
DEFESA