argwrapper(1)

argwrapper(1) Linux Reference Manual argwrapper(1)

NAME

argwrapper - run a binary with environment and arguments sewed into wrapper name

SYNOPSIS

argwrapper [-st chars] [-lL dir] [-AuhV] -- [environ] program [args]

DESCRIPTION

Sometimes there is no possibility to pass additional environment or even command line arguments to a program (e. g. when clicking it from GUI file manager). It's common practice to create an executable shell script wrapping the whole command line like this:


#/bin/sh
ENV1="value 1" ENV2="value 2" ... program "arg 1" "arg 2" ...
There are two problems with shell wrappers. First, generating them automatically is not easy thing to do: one must consider shell special characters quotation etc.

Second, there are situations when shell is unavailable at the moment of execution, e. g. when wrapping qemu-user execution on different architecture.

This application solves both problems.

WRAPPER MODE

When called without parameters, argwrapper assumes it's a wrapper call. It parses it's zero argument (argv[0], usually binary file name) and splits it into series of environment variables assignments, wrapped program name and command line arguments.

Filename format:


AB[CDE...ccddee...]A...[A...[A...]]
where:
  • A - argument separator
  • B - path separator (instead of '/')
  • cc,dd,ee,... - 2-digit hexadecimal codes of characters to replace
  • C,D,E,... - replacement characters for cc,dd,ee,...

The A...[A...[A...]] part is splitted into separate argument list, then each argument is searched for '/' character, as well as for characters with cc, dd, ee... hexadecimal ASCII codes to replace them with B, C, D, E ... characters.

The initial part of the list is treated as environment variable assignments until its elements contain no '=' sign. First element with no '=' sigh is treated as program name and all the trailing part of the list assumed to be command line arguments.

Then environment variables are assigned, ten the prorgam is executed with corresponded arguments.

See EXAMPLES below for particular usage.

NAME GENERATOR MODE

When called with some command line parameters, argwrapper assumes it's a filename generator call. It selects a character for argument separator, a replacement characters for '/' path separator and other optional chars, if any. It's guaranteed that none of the characters selected is appeared within original command line. Then '/' and optional chars are replaced with corresponded replacements and all the arguments are concatenated with argument separator.

The result string is prepended with argument separator, '/' replacement character, replacements for optional chars, two-digit hexadecimal ASCII-codes of optional chars, and another argument separator sequentially, then the result string is printed.

The result string is meant to be wrapper mode filename in the form described above. One can copy, hardlink or symlink argwrapper with that name to gain desired wrapper behaviour.

See EXAMPLES below for particular usage.

OPTIONS

In wrapper mode argwrapper takes no parameters. In name generator mode parameters are:

-A
Select character replacements through letters only.
-s chars
Select character replacements from chars only.
-t chars
Select replacements for chars in addition to '/'.
-l dir
Hardlink wrapper into dir directory.
-L dir
Symlink wrapper into dir directory.
-u dir
Remove wrapper from dir directory.
-q
Be quiet, do not print resulting file name.
-V
Print application name and version.
-h
Print short help.
-H
Print long help.

EXAMPLES

Create a symlink to wrapper that echoes a pair of words, execute, and then remove it silently:


$ argwrapper -L. echo foo bar
_,_echo_foo_bar
$ ./_,_echo_foo_bar
foo bar
$ argwrapper -qu. echo foo bar
Generate a wrapper name with some characters replaced:


$ argwrapper -t " *" echo "First * parameter" "Second **"
_,%@202A_echo_First%@%parameter_Second%@@
Create a symlink to date command wrapper overloading locale and using letter-only separators, execute it an then remove:


$ argwrapper -L. -A LC_ALL=ro_RO date "+%B"
DEDLC_ALL=ro_RODdateD+%B
$ ./DEDLC_ALL=ro_RODdateD+%B
septembrie
$ argwrapper -u. -A LC_ALL=ro_RO date "+%B"
DEDLC_ALL=ro_RODdateD+%B
Generate a wrapper name using custom replacement characters. Space is not replaced until specified directly with -t option. Also note that extra characters and characters that can be found within command line are not used:


$ argwrapper -s ':!.-' echo 'Hello, world!'
:.:echo:Hello, world!

CAVEATS

  • It's better to link argwrapper statically to avoid library dependencies.
  • There is no reason to call argwrapper without arguments directly by primary name.
  • Program name must not contain '=' sign.

AUTHOR

The program is written bu George V. Kouryachy <george@altlinux.org> mainly for Linux binfmt interface support.

SEE ALSO

runas(1), binfmt.d(5)

03 July 2019 argwrapper-0.02