Last active
December 4, 2017 19:40
-
-
Save diogocapela/0145660546f7dc0ed37da2c56f4d7fb5 to your computer and use it in GitHub Desktop.
exercícios da aula
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "--------------------------------------" | |
if [ "$#" -ne 0 ] | |
then | |
echo "Faltam introduzir parametros" | |
fi | |
echo "Número de parametros passados: $#" | |
if [ "$2" -gt "$1" ] | |
then | |
echo "O $2 é o maior" | |
echo "O $1 é o menor" | |
elif [ "$1" -gt "$2" ] | |
then | |
echo "O $1 é o maior" | |
echo "O $2 é o menor" | |
else | |
echo "Os números são iguais" | |
fi | |
mult=$(($1 * $2)) | |
echo "A multiplicação dos 2 números é $mult" | |
echo "--------------------------------------" | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "--------------------------------------" | |
# Get user input (-p de prompt) | |
read -p "Nome do utilizador: " username | |
# Look for the user prompted with who | cut the first row and gret the exact math | |
resultado=$(who | cut -f1 -d " " | grep -i "^${username}$") | |
# Se tem resultado | |
if [ -n "$resultado" ]; then | |
echo "Encontrei o ${username}" | |
else | |
echo "Não encontramos o ${username}" | |
fi | |
# Saida para um ficheiro | |
echo "Olá ${username}" > ${username}_saida.txt | |
echo "--------------------------------------" | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo "--------------------------------------" | |
echo "Número de parametros passados: $#" | |
while [ "$#" != "" ]; do | |
case "$1" in | |
'-c') clear;; | |
'-d') ls;; | |
'-m') nano;; | |
'-e') shift; "$1";; | |
*) echo "Opção $1 não suportada!";; | |
esac | |
shift | |
done | |
echo "--------------------------------------" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment