Issue
In a simple script written in bash the variable project declared within the script:
project='this_is_it'
echo "this is the $project"
how to declare $project
on-the-fly during the script execution directly in terminal (in the responce to the proposition.. ) with the aim to use it subsequently during the workflow execution (so not to declare it without the script) ?
Solution
One possible interpretation of what you are asking -
if you define a variable in front of a command, that variable will be dynamically available for that command, but won't be retained afterwards.
$: env|grep foo # no foo exists
$: foo=bar env|grep foo # foo exists only for this command
foo=bar
$: env|grep foo # no foo remains
$: export bar=foo # set a value that persists
$: env|grep foo # bar's foo exists, but no $foo
bar=foo
$: foo=bar env|grep foo # this has both, but foo still doesn't persist
foo=bar
bar=foo
$: env|grep foo # only bar
bar=foo
$: foo=bar bar=newfoo env|grep foo # overwrites *for this command only*
bar=newfoo
foo=bar
$: env|grep foo # back to as it was
bar=foo
Be wary of using such a variable in the command, however, as the interpreter is not running in the environment that receives the dynamically set variable.
$: foo=bar echo "bar=[$bar] foo=[$foo]" # interpolated before the command
bar=[foo] foo=[]
$: foo=bar bash -c 'echo "bar=[$bar] foo=[$foo]"' # processed BY the command
bar=[foo] foo=[bar]
Answered By - Paul Hodges Answer Checked By - Mildred Charles (WPSolving Admin)