Score:1

Create Directories From String Array

bd flag

I have an array of directory names. I wanna create directories from the array. This is my code.

WATCHED_MOVIE_LIST=("Tenet", "Inception", "Interstellar", "Arrival", "Escape Room")
mkdir ${WATCHED_MOVIE_LIST[*]}

This code will create directories like this.

Tenet
Inception
Interstellar
Arrival
Escape
Room

But Escape Room is a single name. It must create a single folder called 'Escape Room'. However, I want to create directories like this

Tenet
Inception
Interstellar
Arrival
Escape Room

How do I do this in 2 lines of code? (One line is better)

aClassicKoder avatar
th flag
One problem: ```sh WATCHED_MOVIE_LIST=("Tenet", "Inception", "Interstellar", "Arrival", "Escape Room") mkdir "_idk/${WATCHED_MOVIE_LIST[@]}" ``` not work, but i think you want like this https://unix.stackexchange.com/a/426794/541257
Score:1
bd flag

I found a way to do that by doing small changes to my code.

WATCHED_MOVIE_LIST=("Tenet", "Inception", "Interstellar", "Arrival", "Escape Room")
mkdir "${WATCHED_MOVIE_LIST[@]}" 
# '*' replaced with '@'
# Added double quotations to ${WATCHED_MOVIE_LIST[@]}

This code can do my work. Thanks

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.