Assigning a value to a variable on the fly
Tuesday Dec 19 7:28:12 2023
------------------------------
I already told you on other posts that I always start my scripts like
this:
#!/bin/sh
set -e
set -u
set -x
The very next two things are:
# Paths
and
# Variables
I also told you that I really love using positional parameters
because they come in really really handy on many occasions.
Especially if you already know the value of those variables/options
beforehand.
The problem I faced the other day was that I did not know the posible
value of a variable until the script was running. It might sometimes
be expected and then I would include them in a 'case' but what if the
value was not in the 'case' 'esac' statement.
The solution I found was using the 'read' command. I think it is the
best way to do it, the only downside is that it needs user action
when running the script, but well, it is a small prize to pay in my
specific use case this time.
Pretty kewl :)