Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support setting variables in a script #32

Closed
asmacdo opened this issue May 7, 2018 · 2 comments · Fixed by #39
Closed

support setting variables in a script #32

asmacdo opened this issue May 7, 2018 · 2 comments · Fixed by #39

Comments

@asmacdo
Copy link
Contributor

asmacdo commented May 7, 2018

Variables cannot be set within a live script:

$ cat variables.sh

export SET_VAR="Please add support for variables"
echo $SET_VAR

$ doitlive play variables.sh

We'll do it live!
STARTING SESSION: Press Ctrl-C at any time to exit.
Press any key to continue ...
austin@dhcp129-212.rdu.redhat.com:devel $ export SET_VAR="Please add support for variables"
austin@dhcp129-212.rdu.redhat.com:devel $ echo $SET_VAR

austin@dhcp129-212.rdu.redhat.com:devel $ 
FINISHED SESSION

Just as a sanity check...
bash variables.sh

Please add support for variables
@sloria
Copy link
Owner

sloria commented May 8, 2018

@asmacdo You can use #doitlive env: <VAR>=<value> as a workaround.

export NAME=Austin
#doitlive env: NAME=Austin
echo 'Hello' $NAME

Each command run in a session executes in its own environment, so export commands don't persist envvars to the next command. Use the above workaround for now.

Maybe doitlive should parse out export commands and save those variables automatically...

@sloria
Copy link
Owner

sloria commented May 8, 2018

If I get some time this weekend, I'll see if I can make so that export commands work as expected. If you need it sooner, I'd definitely review/merge a PR. I think it's a matter of adding some logic here:

elif shell_match:

Might be as simple as adding an elif command.startswith('export') and then calling state.add_envvar(command.split()[1]).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants