From d4ae19789d49076ef1aac6bc72e7b9af5752bbef Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Mon, 15 Apr 2024 12:38:30 +0300 Subject: [PATCH] bash: add employees.bash (another UAS thing) --- bash/.gitignore | 2 ++ bash/employees.bash | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 bash/employees.bash diff --git a/bash/.gitignore b/bash/.gitignore index c80fff3..d4d10c8 100644 --- a/bash/.gitignore +++ b/bash/.gitignore @@ -4,6 +4,8 @@ *.jpeg # download-forgejo.bash results to these forgejo-* +# employees.bash +employees.csv # submodule symlinks backup-ops2l-vmc.bash generate-vcard-qr.bash diff --git a/bash/employees.bash b/bash/employees.bash new file mode 100755 index 0000000..216f86e --- /dev/null +++ b/bash/employees.bash @@ -0,0 +1,34 @@ +#!/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