Score:0

how to read a file name that icludes spaces

in flag

I want the user to choose the file named "main folder" but if i just use read foldername ls $foldername it just reads the words "main" and "folder" separately (basically executing ls main instead of ls "main folder"how can i make so it includes spaces ? I have tried read -r foldername but no luck

hr flag
Please [edit] your question to include a reproducible snippet showing how you used the `read` command, and how you determined that it reads the words separately
FedKad avatar
cn flag
The culprit is not the `read`, but your usage of the variable `foldername`. Enclose it in double quotes while using it.
Antonis Alzeer avatar
in flag
@steeldriver i think i did what you asked , not really sure if i helped
hr flag
OK so it's not the `read` that's the problem here - it's the unquoted expansion of the variable afterwards - unless you're using `zsh` it needs to be `ls "$foldername"` to prevent word splitting and glob expansion.
Score:1
ng flag

Did you mean: Print the file out to the command line? If yes:

Use cat "filename with spaces.txt" or cat filename\ with\ spaces.txt.

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.