For example, try following command in an empty directory:
$ for i in *; do echo $i; done
*
Is there a way to suppress the printout of
To avoid the *
, you can try something like
for i in `ls`; do echo $i; done
Tried now on an empty directory, no output given...
Basic idea is use ls command, but if filename has space, ls
will split file name by space. In order to handle space in filename, you can do like this:
ls|while read i; do echo $i; done
Aleks-Daniel Jakimenko said "Do not parse ls". Which is good, so how about this if we don't want to change nullglob:
for i in *; do [ -e "$i" ] && echo $i; done
Set nullglob
shopt -s nullglob
for i in *; do echo "$i"; done