-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07-debuger.sh
More file actions
executable file
·70 lines (69 loc) · 1.82 KB
/
Copy path07-debuger.sh
File metadata and controls
executable file
·70 lines (69 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
#
# 07-debuger.sh - Exemplo de debug
#
# site: github.com/ederteixeira
# autor: Éder Teixeira
# Manutenção: Éder Teixeira
#
# --------------------------------------------------------------------- #
# Descrição:
# Debugando o código
#
# Exemplos:
# 1-Debug simples:
# Exemplo por parametros:
# bash -x ./07-debuger.sh -v -s -> Tem uma saída mais simples
# bash -xv ./07-debuger.sh -v -s -> Tem uma saída completa
# Este tipo de debug é utilizado em códigos mais simples
#
# 2-Debug por parte específica ou linha
# set -x -> Informa o início
# set +x -> Informa o fim
# Exemplo por parte:
# set -x
# [ "$CHAVE_MAISCULO" -eq 1 ] && USUARIOS=$(echo "$USUARIOS" | tr [a-z] [A-Z])
# set +x
#
# --------------------------------------------------------------------- #
# Histórico:
# v1.0 30/08/2021 - Éder
# -Inicio do exemplo do debug
# v1.1 30/08/2021 - Éder
# -Ajustando comentários.
#
# --------------------------------------------------------------------- #
#
# Testado em:
# bash 4.4.19
#
# -------------------------- Variáveis -------------------------------- #
USUARIOS=$(cat /etc/passwd | cut -d : -f 1)
MENSAGEM_USU="
$(basename $0)
[OPÇÕES]
-h - Menu de ajuda
-v - Versão
-s - Ordernar
-m - maiúsculo
"
VERSAO="v1.2"
CHAVE_ORDENA=0
CHAVE_MAISCULO=0
# -------------------------- Execução --------------------------------- #
while test -n "$1"
do
case "$1" in
-h) echo "$MENSAGEM_USU" && exit 0 ;;
-v) echo "$VERSAO" && exit 0 ;;
-s) CHAVE_ORDENA=1 ;;
-m) CHAVE_MAISCULO=1 ;;
*) echo "Valor inválido" && exit 1 ;;
esac
shift
done
set -x
[ "$CHAVE_ORDENA" -eq 1 ] && USUARIOS=$(echo "$USUARIOS" | sort)
[ "$CHAVE_MAISCULO" -eq 1 ] && USUARIOS=$(echo "$USUARIOS" | tr [a-z] [A-Z])
set +x
echo "$USUARIOS"