0

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?

Alex
  • 2,555
  • 6
  • 30
  • 48
  • 1
    You probably meant `location=${location/Validated/validated}`. Alternatively (Bash 4.0 or newer), `location=${location,,}` (lowercases everything). – Benjamin W. Aug 07 '19 at 18:31
  • Which words exactly have to be lowercased? Why `Validated`, but not `External`? – Benjamin W. Aug 07 '19 at 18:33
  • @BenjaminW. oh man you're totally right, I assumed the variable had to be expanded but I guess not - that does it! As to your question... dunno! Not my choice, I got handed this file system and am now stuck with it – Alex Aug 07 '19 at 18:34

0 Answers0