Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change argv0 in bash so command shows up with different name in ps?

Tags:

bash

argv

ps

In a C program I can write argv[0] and the new name shows up in a ps listing.

How can I do this in bash?

like image 273
bstpierre Avatar asked Jul 15 '10 00:07

bstpierre


People also ask

Can a bash script modify itself?

One of the requirements I have is that the script must be self contained; no other files are to accompany the script and there are to be no environment variables. This would require the script to be able to edit itself.

What is $s in bash?

From man bash : -s If the -s option is present, or if no arguments remain after option processing, then commands are read from the standard input. This option allows the positional parameters to be set when invoking an interactive shell.


2 Answers

You can do it when running a new program via exec -a <newname>.

like image 158
Ignacio Vazquez-Abrams Avatar answered Sep 30 '22 04:09

Ignacio Vazquez-Abrams


Just for the record, even though it does not exactly answer the original poster's question, this is something trivial to do with zsh:

ARGV0=emacs nethack 
like image 40
Vincent Fourmond Avatar answered Sep 30 '22 05:09

Vincent Fourmond