[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: env: please add argv0 setting feature

From: Pádraig Brady
Subject: Re: env: please add argv0 setting feature
Date: Thu, 2 Mar 2023 15:57:42 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Thunderbird/109.0

On 02/03/2023 12:34, wrote:
I'm using env to control a program's environment for testing purposes.
It allows me control over arguments, environment and input.

     env -i VARIABLE=value program argv1 argv2 argv3

However, I also need control over the program name located at argv0.

     # argv0 is set to "./program"
     env -i VARIABLE=value ./program argv1 argv2 argv3

I'd like to normalize it to "program" for testing purposes.
I'd also like to be able to set it to other values.
So it would be useful if env had support for it. Something like:

     env --name program -i VARIABLE=value ./program argv1 argv2 argv3

I tried to use bash for this but it didn't turn out well.

     # Sets PWD and SHLVL and the latter apparently can't be unset
     env -i VARIABLE=value bash -c 'exec -a program ./program'

     # Sets env's argv0, not my program's
     bash -c 'exec -a program env -i VARIABLE=value ./program'

Are you open to receiving a patch for this feature?

This does seem appropriate for adding to env(1).

Well I'm a bit reluctant given bash supports this already.
Re using bash, the PWD and SHLVL issue seems like edge cases though
and not generally a problem? BTW it seems like SHLVL can be unset here.
Also for the record I notice one can do `ARGV0=blah command` in zsh.

Perhaps --title would be more appropriate, given "name" is mentioned
quite a bit already in the description.

An edge case is we may want to support allowing to specify a NULL argv[0].


reply via email to

[Prev in Thread] Current Thread [Next in Thread]