mirror of
https://gitea.blesmrt.net/mikaela/scripts.git
synced 2025-07-03 12:47:21 +02:00
Compare commits
No commits in common. "d4ae19789d49076ef1aac6bc72e7b9af5752bbef" and "930c8e019b34cf34370000f2fc9d0d0365c300f2" have entirely different histories.
d4ae19789d
...
930c8e019b
2
bash/.gitignore
vendored
2
bash/.gitignore
vendored
@ -4,8 +4,6 @@
|
|||||||
*.jpeg
|
*.jpeg
|
||||||
# download-forgejo.bash results to these
|
# download-forgejo.bash results to these
|
||||||
forgejo-*
|
forgejo-*
|
||||||
# employees.bash
|
|
||||||
employees.csv
|
|
||||||
# submodule symlinks
|
# submodule symlinks
|
||||||
backup-ops2l-vmc.bash
|
backup-ops2l-vmc.bash
|
||||||
generate-vcard-qr.bash
|
generate-vcard-qr.bash
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Ensure we are given three parameters
|
|
||||||
if [ $# -ne 3 ]; then
|
|
||||||
echo "Please run this script like: ./$0 <operand1> <operator> <operand2>"
|
|
||||||
echo "where operator is either +, -, * or /. You may need to escape or"
|
|
||||||
echo "single quote it."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Store the operands and operator
|
|
||||||
operand1=$1
|
|
||||||
operator=$2
|
|
||||||
operand2=$3
|
|
||||||
|
|
||||||
# The main case/switch which was required in the exercise
|
|
||||||
case $operator in
|
|
||||||
'+')
|
|
||||||
result=$((operand1 + operand2))
|
|
||||||
operatorWord="plus"
|
|
||||||
;;
|
|
||||||
'-')
|
|
||||||
result=$((operand1 - operand2))
|
|
||||||
operatorWord="minus"
|
|
||||||
;;
|
|
||||||
'*')
|
|
||||||
result=$((operand1 * operand2))
|
|
||||||
operatorWord="multiplied by"
|
|
||||||
;;
|
|
||||||
'/')
|
|
||||||
if [ "$operand2" -eq 0 ]; then
|
|
||||||
echo "The laws of mathematics don't allow division by zero."
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
result=$((operand1 / operand2))
|
|
||||||
operatorWord="divided by"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
# Let's not forget default case either
|
|
||||||
*)
|
|
||||||
echo "Please use operator +, -. * or /"
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# and finally the output in format wanted by the task
|
|
||||||
echo "$operand1 $operatorWord $operand2 equals $result"
|
|
@ -1,34 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
# Ensure that the file is empty. -n is specified to avoid \n which would
|
|
||||||
# become obvious in the cat in the end.
|
|
||||||
echo -n '' >employees.csv
|
|
||||||
|
|
||||||
# Begin at 0 so the incrementing later makes the first employee id 1.
|
|
||||||
employees=0
|
|
||||||
|
|
||||||
# While the employee name isn't 0, take names.
|
|
||||||
# neovim again complains about backslash dangling and I will probably never
|
|
||||||
# type read without -r
|
|
||||||
while true; do
|
|
||||||
echo "Enter employee name or 0 to stop: "
|
|
||||||
read -r name
|
|
||||||
|
|
||||||
# stops and breaks out of the loop
|
|
||||||
if [ "$name" = "0" ]; then
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
# begin at employee id 1 by incrementing employees from 0
|
|
||||||
employee_id=$((employees + 1))
|
|
||||||
|
|
||||||
# store employee_id and name to employees.csv
|
|
||||||
# I think tsv would be easier and better, but this is what the task requested.
|
|
||||||
echo "$employee_id;$name" >>employees.csv
|
|
||||||
|
|
||||||
# increment employees so the next id will be 2
|
|
||||||
employees=$((employees + 1))
|
|
||||||
done
|
|
||||||
|
|
||||||
# and finally print our document. I stand with tsv being better option.
|
|
||||||
cat employees.csv
|
|
Loading…
x
Reference in New Issue
Block a user