commit 3ae94d86002550d68278cb7059d333535c21bb49 Author: Webmaster Date: Wed May 29 13:29:46 2024 +0200 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..a9b75c7 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# fx' linux scripts +This repo contains different little bash scripts created during the LPIC course in april/may 2024 diff --git a/to_ip4.sh b/to_ip4.sh new file mode 100755 index 0000000..c213c0b --- /dev/null +++ b/to_ip4.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Step 0: Make sure we have an argument +if [ -z "$1" ]; then + echo "Usage: $0 (input string being last two blocks of ip6, e.g. fe36:d00f)" + exit 1 +fi + +input=$1 + +# Step 1: Split the input string at ":" +IFS=':' read -r part1 part2 <<< "$input" + +# Step 2: Pad each of the two fields to 4 characters by adding leading zeros +part1=$(printf '%04x' 0x$part1) +part2=$(printf '%04x' 0x$part2) + +# Step 3: Split each of the four-digit numbers into two digit numbers +# e.g., 4f33 becomes 4f and 33 +part1a=${part1:0:2} +part1b=${part1:2:2} +part2a=${part2:0:2} +part2b=${part2:2:2} + +# Step 4: Translate each hexadecimal two-digit number into decimal +decimal1a=$(printf '%d' 0x$part1a) +decimal1b=$(printf '%d' 0x$part1b) +decimal2a=$(printf '%d' 0x$part2a) +decimal2b=$(printf '%d' 0x$part2b) + +# Step 5: Concat all numbers with a point '.' +result="$decimal1a.$decimal1b.$decimal2a.$decimal2b" + +# Output the result +echo "$result" + diff --git a/var_comparison.sh b/var_comparison.sh new file mode 100755 index 0000000..8df7de1 --- /dev/null +++ b/var_comparison.sh @@ -0,0 +1,14 @@ +#!/bin/bash +same=0 +sSet=$(set | grep -E "^\w+=") +sEnv=$(env | grep -E "^\w+=") + +echo "set: $(wc -l <<<$sSet) variablen" +echo "env: $(wc -l <<<$sEnv) variablen" + +for v in $sEnv; do + if echo "$sSet" | grep -q "$v"; then + ((same++)) + fi +done +echo "$same variables in both set and env"