1

I'm trying to get a list of directory names in i. For example,

for i in `ls`
do

However, ls accesses a directory which contains multi-word directories, people's names, John Doe. If I just use `ls`, then a two word name becomes two values for i. If I use "`ls`", I get one long string of all the names in i. I tried using "ls -1" to force one line per entry but that didn't work either. Is there a solution?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
rbpeirce
  • 11
  • 1
  • 2
    [This article](https://mywiki.wooledge.org/ParsingLs) explains why parsing `ls` is a problem; use `for i in ./*` instead (and then refer to `i` with double quotes, `"$i"`). There has to be a duplicate somewhere... – Benjamin W. Jan 13 '20 at 22:55
  • https://stackoverflow.com/q/20796200/3266847 and https://stackoverflow.com/q/8512462/3266847 are similar, but not *exact* duplicates – Benjamin W. Jan 13 '20 at 23:01

0 Answers0