1

I am building a program which helps in memory debugging of C programs. I call

execlp("gnome-terminal","gnome-terminal","-e",command,(char*)0);

to open a new terminal window where the program to be debugged runs. I do this to not have my debugging info intermixed with the users program output. Because I need to set up an environmental variable before running the users program, command var is actually the name of the shell script where I pass the users program as the first arg.

Here is my script:

#!/bin/bash

export LD_PRELOAD="./mylib.so"
$1

This works fine for programs with no arguments but what happens if the user also supplies args with his program?

For example I wish to call my script like that :

myScript.sh usersProgram arg1 arg2 etc

How can I correctly run the users program inside the script and pass all the arguments to it?

Thank you

2 Answers 2

5

Use "$@", which will handle all arguments properly.

Sign up to request clarification or add additional context in comments.

Comments

3

Assuming that args to program always start from the 2nd arg, I'd suggest doing it like this:

#!/bin/bash

PROG=$1
shift
$PROG "$@"

Practically, just specifying "$@" instead of the three lines above will also work. But this way, you can easily do some manipulation based on $PROG before actually executing it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.