Tibor Vass
Tibor Vass

Reputation: 167

Is it possible to access the value associated with the "-c" parameter from a bash script?

I would like to do bash -c '<some smart bash script>' that would output the actual string passed to -c.

In other words, if SCRIPT is set to that smart script, bash -c "$SCRIPT" should yield what's in $SCRIPT.

Is that possible? If yes, how?

Thanks

Upvotes: 1

Views: 338

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74078

See man bash

5.2 Bash Variables
...
BASH_EXECUTION_STRING
The command argument to the -c invocation option.

If you try

bash -c 'echo $BASH_EXECUTION_STRING'

it will give you

echo $BASH_EXECUTION_STRING

Upvotes: 5

Related Questions