A
A
alex stephen2015-07-15 15:38:20
bash
alex stephen, 2015-07-15 15:38:20

Console: how to output files with spaces?

Probably, the question is already beaten, but still, I did not find a normal solution.
There is a folder in which there are files with names in Russian, and with spaces (and other terminal special characters) in the names.
ls -1
works fine
for name in `ls -1`; do echo $name;done;
displays everything in chunks.
How to fix it?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DevMan, 2015-07-15
@berezuev

SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for name in `ls -1`; do echo $name;done;
IFS=$SAVEIFS

A
Alexey Sergey, 2015-07-15
@dev_random

you can just wrap `ls -1` and $name with double quotes:
for name in "`ls -1`"; do echo "$name";done;

A
Azazel PW, 2015-07-15
@azazelpw

write the results to a file
#!/bin/bash
path=/home/user
ls -1 $path > /var/log/list.log
for name in `cat /var/log/list.log`;
do
echo $name;
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question