initial commit

This commit is contained in:
Webmaster 2024-05-29 13:29:46 +02:00
commit 3ae94d8600
3 changed files with 52 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# fx' linux scripts
This repo contains different little bash scripts created during the LPIC course in april/may 2024

36
to_ip4.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
# Step 0: Make sure we have an argument
if [ -z "$1" ]; then
echo "Usage: $0 <input_string> (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"

14
var_comparison.sh Executable file
View File

@ -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"