Bash parses the command line input into words. It executes the first word and passes the rest of them to it as an array. Its up to the program to process this array. Most programs will accept an undefined number of arguments. It is pretty standard that the flags need to come before the arguments.
It is customary to group short options and to interpret every argument that starts with a dash as an option. Short flags start with a
- and can be combined while long flags start with
-- and cannot. In the case of a sequence of files that needs to be explicitly marked, it is also customary to insert
-- before the list to signal that no options will follow.
Most programs with a simple command line syntax use the
getopt(3) function in the C library on Unix. This function handles basic parsing and behaves as described above.
ls -lahFG) or it requires them separately (
ls -l -a -h -F -G).
-as a flag and would happily accept
exec dirpath -F.
ls dir -Fshould work according to the logic above. It is up to ls that it does not.
convert. An average option is just a boolean flag and an average program does not have semantically overlapping flags. When the flags do overlap, they take effect from first to last. With overlapping booleans, only the last one would take effect (but that's up to the program).
--long=paramsyntax while compiled programs use
gcc -vomit-frame-pointer. Programs with excessively many options always never follow the long option convention.
git. The well behaved breeds (
ip) will let you shorten the subcommands until they become ambiguous:
btrfs bal starinstead of
btrfs balance start,
btrfs fi sh /pathinstead of
btrfs filesystem show /pathor
svn statinstead of
svn status. Git does not accept shorthands, partly due to the underlying architecture.
gcchas its own option system.
-f<opt>options control optimisation types and code transformations,
-W<opt>control which warnings show, etc. One of the options is
-fomit-frame-pointer(do not save the frame pointer in function call, which makes life harder for the debugger but speeds up function calls).
With a basic understanding of Bash and programming, you should be able to explain why there can not be less whitespace in the following (except for the cosmetic ones after ;):
if [ "$USER" == "$(id -nu)" ]; then echo tautology; fi
The following code works in the DOS shell, but not on Unix.
On Windows, they probably made a special case or they do not treat a dot as a part of a word. A Unix shell tokenises according to whitespace. In this case, it would try to run a program called
cd.., which does not exist.
What's really going to bake your noodle later on: you can not write a program like that, because the current working directory is a runtime attribute of a process. Such a program could only change its own current working directory and not also its parent shell's. After the program terminated, the shell would return you to the directory in which you started the program. All paths (except those starting with
/) are resolved with respect to the current working directory.