Reputation: 4695
I suspect this has to do with my oh-my-zsh
setup on my Mac, but I am not able to figure out. When I do ls *.sh
on command line, I get something like:
foo.sh* bar.sh*
I understand that by default, -F
is applied on ls
:
-F Display a slash ('/') immediately after each pathname that is a directory, an asterisk ('*') after each that is executable, an at sign ('@') after each symbolic link, an equals sign ('=') after each socket, a percent sign ('%') after each white-out, and a vertical bar ('|') after each that is a FIFO.
I really want to list the file names without their classifiers. This is desirable because without that, my for
:
for f in `ls *.sh`
do
wc -l $f
done
breaks on executable shell scripts (because of the trailing *
):
wc: foo.sh*: open: No such file or directory
wc: bar.sh*: open: No such file or directory
Of course, I can easily work around this. I just wanted to know if I can take care of it on the output of the ls
command. Also, this works fine when my shell is bash
.
Upvotes: 1
Views: 1514
Reputation: 18389
There is no need to use ls
in order to generate a list of matching files. You can just use the pattern directly:
for f in *.sh
do
wc -l $f
done
This also has the advantage to work with filenames that contain spaces.
Generally speaking: the output of ls is for human consumption, it should never be parsed. Usually file lists can be generated directly with globbing and any information ls
might provide can be retrieved by other means (e.g. stat
).
That being said:
-F
is not enabled by default, hence why there is an option for that. I suspect that ls
is an alias. You can check with
whence -v ls
While oh-my-zsh by default creates an alias to ls
, -F
is not part of the settings.
If you just want to use an unmodified ls
(maybe with different options) you can prepend the command
precommand modifier:
command ls
This will run the external command ls
(usually /bin/ls
) instead of an alias or a function.
If you want to get rid of -F
permanently, you can either overwrite it somewhere at the very end of your configuration. Or you track down where it is set and change it there. This command might help in finding where the alias is set:
grep -r $(whence ls) ~/.zshrc ~/oh-my-zsh.sh ~/.oh-my-zsh
Depending on your setup there might be additional configuration files.
Upvotes: 3