Quantcast
Channel: Why *not* parse `ls` (and what to do instead)? - Unix & Linux Stack Exchange
Browsing all 11 articles
Browse latest View live

Answer by godlygeek for Why *not* parse `ls` (and what to do instead)?

Is it possible to parse the output of ls in certain cases? Sure. The idea of extracting a list of inode numbers from a directory is a good example - if you know that your implementation's ls supports...

View Article



Answer by shelleybutterfly for Why *not* parse `ls` (and what to do instead)?

OP's Stated Intention Addressed preface and original answer's rationale†updated on 2015-05-18 mikeserv (the OP) stated in latest update to his question: "I do consider it a shame though that I first...

View Article

Answer by Voo for Why *not* parse `ls` (and what to do instead)?

The reason people say never do something isn't necessarily because it absolutely positively cannot be done correctly. We may be able to do so, but it may be more complicated, less efficient both space-...

View Article

Answer by zwol for Why *not* parse `ls` (and what to do instead)?

I am not at all convinced of this, but let's suppose for the sake of argument that you could, if you're prepared to put in enough effort, parse the output of ls reliably, even in the face of an...

View Article

Answer by user41515 for Why *not* parse `ls` (and what to do instead)?

The output of ls -q isn't a glob at all. It uses ? to mean "There is a character here that can't be displayed directly". Globs use ? to mean "Any character is allowed here". Globs have other special...

View Article


Answer by Braiam for Why *not* parse `ls` (and what to do instead)?

The answer is simple: The special cases of ls you have to handle outweigh any possible benefit. These special cases can be avoided if you don't parse ls output. The mantra here is never trust the user...

View Article

Answer by terdon for Why *not* parse `ls` (and what to do instead)?

Let's try and simplify a little: $ touch a$'\n'b a$'\t'b 'a b' $ ls a b a?b a?b $ IFS=" " $ set -- $(ls -1q | uniq) $ echo "Total files in shell array: $#" Total files in shell array: 4 See? That's...

View Article

Answer by Patrick for Why *not* parse `ls` (and what to do instead)?

That link is referenced a lot because the information is completely accurate, and it has been there for a very long time. ls replaces non-printable characters with glob characters yes, but those...

View Article


Why *not* parse `ls` (and what to do instead)?

I consistently see answers quoting this link stating definitively "Don't parse ls!" This bothers me for a couple of reasons: It seems the information in that link has been accepted wholesale with...

View Article


Answer by waltinator for Why *not* parse `ls` (and what to do instead)?

I "don't parse ls" because:Filenames can contain any ASCII character except / and NUL (0x00). ls ouputs a multi-character representations of strange characters. This must be reversed (undone) before...

View Article

Answer by Fravadona for Why *not* parse `ls` (and what to do instead)?

Added for completeness sakeThere's a trick called “slash dot saves the day” which consists in using /./ as a magic anchor for determining if a newline was produced as a record separator or due to...

View Article
Browsing all 11 articles
Browse latest View live




Latest Images