Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Choosing program invocation name

Status
Not open for further replies.

chipperMDW

Programmer
Mar 24, 2002
1,268
US
I seem to remember a utility or shell builtin that allows you to execute a command and "fake" the program invocation name (that is, what would go in a C program's [tt]argv[0][/tt]).

This facility exists because many programs behave differently based on how they are invoked. Most shells, for example, run as login shells when they are invoked with a name beginning with a dash. Programs like [tt]zip[/tt] and [tt]unzip[/tt] are typically the same executable, and decide how to behave by the name used to invoke them. (Though in that particular case, the "name-faking" is normally done by creating symlinks).

Anyway, I can't figure out the name of that utility. Can someone refresh my memory, please?
 
A hardlink (ln) ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
No.

I would examine [tt]$0[/tt] to find the name used to invoke a script, whereas I'm looking for a utility that lets me invoke a program using a name that differs from the name of its executable file.


To clarify:

There's some utility that can be used in a manner similar to this:
Code:
invokeas foo bar arg1 arg2 arg3

That line would invoke the program [tt]bar[/tt], passing it the [tt]arg[/tt]s.

However, when [tt]bar[/tt] examines its arguments to discover the name used to invoke it, it will find [tt]foo[/tt], not [tt]bar[/tt].

[tt]invokeas[/tt] is a made-up name for this command, as I cannot remember its true name. I'm looking for that name.
 
PHV,

Making a hard link would allow one to execute a program under a different name, but I was looking for the command to actually execute a program using an arbitrarily chosen name, as shown in my above example.


I found something close to what I was thinking of. [tt]exec -a[/tt] allows one to run a program and give it an arbitrary name.

However since [tt]exec[/tt] of course replaces the current shell with the [tt]exec[/tt]ed command, my above example is equivalent to:
Code:
sh -c "exec -a foo bar arg1 arg2 arg3"

What I'm remembering is a similar command that uses the syntax shown for the mythical [tt]invokeas[/tt] command in my example. That's what I'm looking for.
 
Well, you could easily write a utility to this, as there is an exec that takes the command and argument string (which includes argv[0] )...

I know that there is command already, but I can't think of it off the top of my head...
 
This ?
(exec -a foo bar arg1 arg2 arg3)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Yeah, that'd work, and is pretty much equivalent to my second example.

Like I said, though, I'm not looking for some way to make it work. I know multiple ways of making it work. I could write a small shell script that has the functionality of my mythical [tt]invokeas[/tt] command by creating a temporary symlink, or by using [tt]exec -a[/tt]. I could similarly write a C program to do the same.

None of those help me, however, because my question isn't about accomplishing the task. My question is about a command name I cannot remember.

Again, what I'm looking for is the name of a certain already existing command that has the syntax of the mythical [tt]invokeas[/tt] used in my first example.
 
Your not thinking of alias are you (I don't think you are, because it doesn't execute anything). I just thought of it b/c I thought it's man page might have a see also to the command you want, but it doesn't (at least on Debian linux).
 
Nope.

I'm thinking it was named something like "runas" or "callas," but it doesn't appear to be either of those. I looked through the command names on my system that end in "as" and couldn't find anything.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top