For I school project, I have to implement a shell/terminal app. But I am wondering how are command line options parsed, because it appears abit weird to be. For example for the command paste (and I believe other utilities behave similarly)
[jiewmeng@JM tmp]$ paste --help
Usage: paste [OPTION]... [FILE]...
Behavior when combining multiple options into one
[jiewmeng@JM tmp]$ paste -ds file1
file1 xxx
file1
d aaws dafd a
Here it appears options are just ignored ...
[jiewmeng@JM tmp]$ paste -sd file1
It behaves the same as paste -
, waiting for stdin
. But when its valid combination
[jiewmeng@JM tmp]$ paste -sd. file1
file1 xxx.file1.d aaws dafd a
It works. Shouldn't the invalid one give an error instead of waiting for stdin
?
[jiewmeng@JM tmp]$ paste -d
paste: option requires an argument -- 'd'
Try 'paste --help' for more information.
Ok, makes sense d
requires an argument, but ...
[jiewmeng@JM tmp]$ paste -d file1
... waits for stdin
. why?