Vahid Vahid - 5 months ago 9
Linux Question

Always call a binary with a specific flag in linux

I was wondering if there is any way to execute a binary in linux, always with a specific flag.

For example, whenever

genisoimage
executes, I want it always executes with
-allow-limited-size
flag. So, issuing the
genisoimage
in console, results in
genisoimage -allow-limited-size
run.

alias
won't work as the binary is called from another one

Answer

Yep! What you're looking for is a Bash alias.

Just add alias genisoimage="genisoimage -allow-limited-size" to your ~/.bashrc (or ~/.bash_profile for macOS) file.

For more info on the Bash alias, check out http://www.tldp.org/LDP/abs/html/aliases.html?cachebusterTimestamp=1466192028407

EDIT: Given that another script or application calls genisoimage.

If it's being called form another script or application, you're going to have to change the genisoimage that's resolved within that script/application. Here's how you may be able to accomplish this.

First, Create your own genisoimage which adds your -allow-limited-size flag. This will go in to a file named genisoimage at /some/other/path and must be made executable (i.e. chmod u+x /some/other/path/genisoimage). Suppose that the genuine genisoimage file is located at /bin/genisoimage

#! /bin/bash
/bin/genisoimage -allow-limited-size "$@"

The above adds the desired flag, and passes all arguments along to the origin genisoimage.

Now when you run your script/application, change the PATH variable so the file you just created is found first.

$> PATH=/some/other/path:$PATH ./APPLICATION