This commit is contained in:
kyodev 2018-06-28 09:30:38 +02:00
parent f01893c92f
commit 47861ef1a8
2 changed files with 46 additions and 22 deletions

View File

@ -1,7 +1,7 @@
# getIp
![version: 2.15.1](https://img.shields.io/badge/version-2.15.1-blue.svg?longCache=true&style=for-the-badge)
![version: 2.16.0](https://img.shields.io/badge/version-2.16.0-blue.svg?longCache=true&style=for-the-badge)
![bash langage](https://img.shields.io/badge/bash-4-brightgreen.svg?longCache=true&style=for-the-badge)
![license LPRAB / WTFPL](https://img.shields.io/badge/license-LPRAB%20%2F%20WTFPL-blue.svg?longCache=true&style=for-the-badge)

View File

@ -1,7 +1,7 @@
#!/bin/bash
version=2.15.1b
date="25/06/2018"
version=2.16.0
date="28/06/2018"
script="getIp"
# contact="IRC ##sdeb@freenode.net ou https://framagit.org/sdeb/getIp/issues"
@ -234,21 +234,45 @@ f__user(){ # 08/03/2018
return 0
}
# $1='-l' comptage ligne dans variable $2, affiche quantité
# $1='-w' comptage dans variable $2 des mots
# $1='-wv' comptage dans variable $2, des mots $3, affiche quantité
# f__wcv -l $var ; f__wcv -w $var ; f__wcv -wv $var "mot"
f__wcv(){ # 09/03/2018
# $1='-l' lines, comptage ligne NON VIDE dans $var, affiche quantité de lignes NON VIDES
# si supplément -alnum, seules les lignes commençants pas des caractères alphanumériques sont comptabilisées
# $1='-w' words, comptage dans $var des mots, affiche quantité de mots dans $var
# $1='-o' occurrences, comptage dans $var, du <mot>, affiche quantité de <mot> dans $var
# f__wc -l $var | f__wc -w $var | f__wc $var -o <mot> ou f__wc -o <mot> $var
f__wc(){ # 28/06/2018
local data todo counter stck scan
[[ "$1" =~ -l|-wv|-w ]] || echo "erreur f__wcv \$1 ($1) incorrect"
if [ "$1" == "-l" ]; then
grep -cEv '^[[:space:]]*$' <<< "$2" # (wc -l compterait 1 pour une variable vide)
elif [ "$1" == "-w" ]; then
result=$( xargs <<< "$2" | grep -o '[[:graph:]][[:blank:]][[:graph:]]' | grep -c ' ' )
[ "$result" -ne 0 ] && result=$(( result+1 ))
echo "$result"
elif [ "$1" == "-wv" ]; then
grep -o "$3" <<< "$2" | grep -c .
while (( $# )) ; do
case "$1" in
-l ) todo='line' ;;
-alnum | -an ) alnum='yes' ;;
-w ) todo='words' ;;
-o ) todo='words_variable'; occurrence="$2" ; shift;;
* ) data="$1" ;;
esac
shift
done
while read -r; do
if [[ $todo == line && ! $REPLY =~ ^[[:blank:]]*$ ]]; then # wc -l compterait 1 pour une variable vide
[[ "$alnum" && ! $REPLY =~ ^[[:alnum:]] ]] && continue
(( counter++ ))
elif [[ $todo == words || $todo == words_variable ]]; then
stck+="$REPLY "
fi
done <<< "$data"
if [ "$todo" == 'line' ]; then
echo $(( counter ))
elif [ "$todo" == 'words' ]; then
read -ra stck <<< "$stck"
echo $(( ${#stck[@]} ))
elif [ "$todo" == 'words_variable' ]; then
read -ra stck <<< "$stck"
for scan in "${stck[@]}"; do
[[ $scan =~ $occurrence ]] && (( counter++ ))
done
echo $(( counter ))
fi
}
@ -646,22 +670,22 @@ fi_ip(){ # 16/06/2018
f_pr titre1 "IPv4"
f_pr l2 "$fg_ip"
f_pr
if [ "$(f__wcv "-l" "$fg_gws")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
if [ "$(f__wc -l "$fg_gws")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
f_pr l2 "passerelle$pluriel: ${fg_gws//$'\n'/ ⊗ }"
f_pr
figet_ip "-6"
f_pr titre1 "IPv6"
f_pr l2 "$fg_ip"
f_pr
if [ "$(f__wcv "-l" "$fg_gws")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
if [ "$(f__wc -l "$fg_gws")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
f_pr l2 "passerelle$pluriel: ${fg_gws//$'\n'/ ⊗ }"
f_pr
if [ "$(f__wcv "-w" "$fg_ifn_prior")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
if [ "$(f__wc -w "$fg_ifn_prior")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
f_pr l2 "interface$pluriel sortante$pluriel ipv6: $fg_ifn_prior" '[ "$fg_ifn_prior" ]'
if [ "$(f__wcv "-w" "$ifn_p4")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
if [ "$(f__wc -w "$ifn_p4")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
f_pr l2 "interface$pluriel sortante$pluriel ipv4: $ifn_p4" '[ "$ifn_p4" ]'
f_pr
if [ "$(f__wcv "-l" "$fg_mac")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
if [ "$(f__wc -l "$fg_mac")" -gt 1 ]; then pluriel="s"; else unset pluriel; fi
f_pr titre1 "adresse$pluriel Mac:"
f_pr l2 "$fg_mac"
f_pr '[ "$fg_ip_deprec" ]'