I am writing a script to move around a bit of data, which I want to be able to create the parent directory to where I am sending my data, in order to do some renaming/cleaning of filenames I need to keep track of the newly created directories so I can change the permissions to the set input argument.
Seeing as
mkdir -vp
can output the created directories it felt perfect, however, I am unable to dereference the quotes to be able to use the output, and eval
seems the only option. I am aware that I could probably just loop and check if each directory exist, but it seems wasteful when mkdir
outputs it already.
This is my code as of now:
readarray -t ndir < <(ssh myhost mkdir -vp foo/ | grep -oP "^mkdir: created directory\s+\K['\"].+['\"](?=$)" | sort -r)
eval ndir=("${ndir[@]}")
ssh myhost chmod 555 "${ndir[@]}"
EDIT: If foo
was a path with newlines, or other special character they will be quoted in $'..'
format, which is why I started using eval.
It is my understanding that eval
is as close to evil as you can come, but I don't see any viable and as convenient solution other than manually looping over and checking which parts of the path exist. Is there a safer, and alternative way?
Asked by Caesar
(25 rep)
Nov 21, 2024, 12:55 AM
Last activity: Nov 23, 2024, 08:52 AM
Last activity: Nov 23, 2024, 08:52 AM