Score:1

Bash slash does't work in wildcards square brackets

ad flag

I'm curious why command ls -pd *[!/] or ls -pd *[!\/] doesn't match all files which don't end with /.

My use case is that I want to list only files inside the current working directory. I know that it's better to use find instead of ls but I want to understand in general is it possible to use / in square brackets in wildcards.

fo flag
You might get more traction on this question on stackoverflow
fo flag
In the manual, [Filename Expansion](https://www.gnu.org/software/bash/manual/bash.html#Filename-Expansion) says "When matching a filename, the slash character must always be matched explicitly by a slash in the pattern". Other than that, I can't find anything that says `*/` only expands to directories. Note that the slash is not actually part of the filename. Having said all that, I don't know how to formulate a glob pattern that excludes directories.
fo flag
perhaps `ls -pd1 * | grep -v '/$'`
Alex Misiulia avatar
ad flag
@glennjackman thanks for the answer. But it's strange that's it's not documented in the manual or other sources. I can match other special characters with quoting them in square brackets. But back slash doesn't work.
ph flag
@AlexMisiulia The slash isn't actually part of the filename, it's a delimiter *after* the filename, so it's inherently going to act differently from characters that're part of the filename.
Alex Misiulia avatar
ad flag
@GordonDavisson thanks. Maybe you have some reference to documentation which can describe deeply this topic?
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.