SpecsOS: OS X;Client: Terminal;Shells: sh, bashProblemI'm writing a shell script that adds a layer of abstraction to the ls command. I want to make it unbreakable, so I started by figuring out every possible command that ls can accept (via [ls(1) - Linux manual page][1]) so I can perform another layer of validation/control on options passed via the command line.Before getting too far into my script, I decided to see what the normal functioning of ls was for some long option (double hyphen). I tried a number of them, each one failing in one way or another. For example, the output of running ls --ignore-backups is: <dir> <username>$ ls --ignore-backupsls: illegal option -- -usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]The above about was the same whether I ran via sh or bash (which I know obvious to more experienced users).At this point, I ran man ls, which showed me that only single-letter options are accepted by the version of ls on my machine.QuestionsHow might I go about making my script universal?Generally, when passing command line arguments to an underlying UNIX/Linux command, is there an accepted standard library on which to base one's efforts?Am I missing some essential understanding of UNIX/Linux command library?NOTE: I'm relatively new to shell scripting and am not sure if I'm even asking the right question(s).
Universal abstraction of ls
shell script;ls
If you are developing and targeting OS X, better to look at OS X ls manual page, not Linux one and stick to the options documented there.Alternatively, if you want your script to unbreakably work on every Unix implementation, you are more or less doomed. While there is a common set of options you'll find in all implementations which are the ones defined by POSIX, there are certainly many non standard extensions, like the GNU double hyphen ones but also single character options that might be specific to a ls dialect and/or operating system. There is no generic and portable way to identify the options supported by a given command implementation.