3

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

jfs
  • 399,953
  • 195
  • 994
  • 1,670
Vahid Noormofidi
  • 748
  • 10
  • 17

1 Answers1

3

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
  • The problem is that the binary is called internally from another application. – Vahid Noormofidi Jun 17 '16 at 19:39
  • @Vahid I just updated my answer to take that into account. – Joshua Toenyes Jun 17 '16 at 20:05
  • Thanks @Joshua, so there is not way that with the combination of soft links and alias I can do that, right? – Vahid Noormofidi Jun 17 '16 at 20:10
  • 1
    I think it depends on how much control you have over the "application" or "script" that's calling `genisoimage`. You may also be able to just use a variable in that script (see http://askubuntu.com/questions/98782/how-to-run-an-alias-in-a-shell-script?cachebusterTimestamp=1466194408680). But, it seems like you don't have that control (given the question) so something like I've outlined above is the best I can come up with. – Joshua Toenyes Jun 17 '16 at 20:14