I need to ensure a directory is always created lowercase, regardless of what the user inputs. Here's some sample inputs:
./1A_Internal/foo/bar/baz/
./External/wizz/bang/baz/
./Validated/bink/bank/bonk/
./validated/foo/bang/bonk/
(I have no control over input, I just need to accommodate whatever comes in)
In this case, I need only Validated
to be converted into lowercase validated
. Everything else needs to stay the case it is.
Assuming the path is stored in a variable location
, I thought this would be:
location=$($location/Validated/validated)
but I get either Bad substitution
, or in some cases
-bash: ./Validated/bink/bank/bonk//Validated/validated: No such file or directory
depending on how I tweak it.
I looked for awk or sed solutions but again everything seems to trip up on the fact that my variable has /
's. I'm open to any solution that will work in bash.
My current thought is grepping the string for case-insensitive "validated", using awk to split it if found, and re-connecting it with lowercase validated (even if it already was lowercase), but this seems so complicated - is there not something easier?