CITS2002 Systems Programming  
prev
next CITS2002 CITS2002 schedule  

Parsing command-line arguments

By convention, most applications support command-line arguments (commencing with a significant character) that appear between a program's name and the "true" arguments.

For programs on Unix-derived systems (such as Apple's macOS and Linux), these are termed command switches, and their introductory character is a hyphen, or minus.

Keep in mind, too, that many utilities appear to accept their command switches in (almost) any order. For the common ls program to list files, each of these is equivalent:

  • ls   -l -t -r  files
  • ls   -lt -r  files
  • ls   -ltr  files
  • ls   -rtl  files

Of note, neither the operating system nor the shell know the switches of each program, so it's up to every program to detect them, and report any problems.

 


CITS2002 Systems Programming, Lecture 18, p3, 2nd October 2023.