syntax error syntax error - 2 months ago 10
Bash Question

Passing command line arguments in to a bash script command

Lets say I have a variable storing the name of a compiled C++ program.

executable="myprog.out"


My script
tt
needs to create a transcript of the C++ program and exit it (without the user having to type
exit
to exit the bash
script
command).

So far I've achieved this by doing by calling the bash
script
command inside
tt
script like so,

#!/bin/bash
script -q -c $executable transcript


This method works provided that the C++ program doesn't take command line arguments. If I have a variable holding the command line arguments needed for the program as,

progArgs="arg1"


How do I call the script command and have it enter the command line arguments for
$executable
?

Answer

The -c option actually takes a shell command as its argument, so you can pass arguments like that:

script -q -c "$executable --opt1 --opt2 -f test" transcript
Comments