4

GNU ps supports BSD-style options, UNIX-style options, and GNU long options. Is using one of these types (in scripts and at the command line) preferred over the others?

I get the impression from the manpage that the functionality of the option styles does not overlap completely.

Jim Hunziker
  • 1,802
  • 4
  • 17
  • 18

4 Answers4

2

Generally speaking just use the set of options that gives you the results you want.

For the sake of (other people's) sanity & portability I suggest sticking with BSD-style or SysV-style arguments -- for the most part modern systems accept both of those argument sets, and that way when the script you wrote to solve a problem on Linux gets dropped onto a system that doesn't understand GNU-style long options it still works (all the world is not a Linux machine).

voretaq7
  • 79,345
  • 17
  • 128
  • 213
1

Is using one of these types (in scripts and at the command line) preferred over the others?

This largely depends on the target platforms your scripts should run on. If your scripts should run only on Linux go with the GNU-style options, if they should also be usable on *BSD go with the BSD-style options and last but not least if they should run on a wide range of unixoid systems (e. g. Solaris) go with the UNIX-style options.

joschi
  • 20,747
  • 3
  • 46
  • 50
1

Whatever POSIX says. I'm not up to stuff on this, but I would guess scripts using ps won't be very portable anyway.

alex
  • 1,329
  • 6
  • 9
0

I think you will find the POSIX or SVR4 options are far more common.

I generally parse uname output, and select the correct /bin/ps, /usr/bin/ps and arguments based on that value. On unsupported platforms, I just exit, I don't guess. On linux, I set $PS_PERSONALITY to "posix" and unset $I_WANT_A_BROKEN_PS in case a user has that set for some reason. This is just a defensive measure.

The GNU getopt_long() style is useful only on Linux, and even if that's what you're going for, people are far more familiar with the short options.