1

When I run the ps command i get a warning saying Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ.

How do i suppress this warning? Is there some system setting that i must do for this. The command that I fire is:

[root@localhost home]# ps -aux | grep "curl -s -o Test" 
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.7/FAQ
root      4856  0.0  0.0   4044   672 pts/0    S+   07:20   0:00 grep curl -s -o Test
[root@localhost home]# 

Note that I have to fire the exact same command as above(I cannot change the -aux to aux, I cannot redirect STDERR output). That is why i am looking for some system setting that will suppress the warning.

4
  • 3
    ps -ef (POSIX/SysV) or ps aux (BSD). Choose your side. Commented Aug 20, 2014 at 19:43
  • This command is fired by a subroutine that i call from my script. I cannot change the subroutine. The subroutine further expects no such warning. Hence i cannot change the command. Commented Aug 20, 2014 at 19:46
  • It seems like the bug is in the script, it's calling ps incorrectly.
    – Barmar
    Commented Aug 20, 2014 at 20:45
  • So the subroutine is written in such a way that generates a warning and also cannot handle that warning? Why would you be required to use this subroutine when it sounds like it could never possibly succeed on your system?
    – dg99
    Commented Aug 20, 2014 at 21:54

3 Answers 3

2

Linux's ps command can emulate ps implementations from various Unix flavors. Set the environment variable PS_PERSONALITY to bsd to make it silently accept -aux as meaning “list all processes using the traditional BSD column set”. From a shell script:

PS_PERSONALITY=bsd /command/you/cannot/modify

From C:

setenv("PS_PERSONALITY", "bsd", 1);
function_you_cannot_modify();
unsetenv("PS_PERSONALITY");
0

The ugly answer is: write a script that takes arguments that look like ps arguments, sanitizes them (at a minimum, replaces -aux with aux), and then calls /bin/ps with the sanitized arguments.  Call it ps and put it in your private bin directory.

0

You write the ps command is part of a subroutine - this solution works if it is a shell function you call, or a shell script you source; It does not work if you execute the shell script containing the ps command.

You can define a shell function with the name ps, that replaces the command in path, and calls the real command itself, with some modifications of the output, like redirecting the STDERR:

function ps() {
    command ps "$@" 2>/dev/null
}

An example using ls:

$ ls -d /etc /missing
ls: cannot access /missing: No such file or directory
/etc
$ function ls() {          
    command ls "$@" 2>/dev/null
}
$ ls -d /etc /missing
/etc

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .