Home > OS >  Create Linux executable without options from Linux executable with specific options
Create Linux executable without options from Linux executable with specific options

Time:12-13

I have an executable in Linux, lets call it run_program that takes some options, e.g. -i 7. I want to test this executable using testing software that also comes as an executable, lets call it run_test. However, this testing software can only take the executable without options. So calling ./run_test -s { run_program -i 7 } does not work (I am not even sure that the way I parenthesized is correct but I was told that passing options with run_program is not going to work anyway).

The executables were compiled using g if that makes a difference.

My idea is to create a new binary that does what a call to run_program -i 7 would otherwise do, using bash. Can anyone more knowlegabele than me in bash tell me how that might work?

I am also open for different solutions!

CodePudding user response:

Create a wrapper script with the content

#!/bin/bash
exec /path/to/run_program -i 7

Make the script file executable, and run

./run_test -s ./wrapper_script

CodePudding user response:

Based on the (so far) confusing/limited input I'm leaning towards a function, eg:

my_test() {
    run_test -s $1          # effectively ignore anything past the 1st argument
}

# or as a one-liner:

my_test() { run_test -s $1; }

Taking for a test drive:

my_test run_program -i 7    # should result in: run_test -s run_program
  • Related