Consider the following shell script on example.com
#/bin/bash
export HELLO_SCOPE=WORLD
eval $@
Now, I would like to download and then execute this shell script with parameters in the simplest way and be able to launch an interactive bash terminal with the HELLO_SCOPE variable set.
I have tried
curl http://example.com/hello_scope.sh | bash -s bash -i
But it quits the shell immediately. From what I can understand, it's because curls stdout
, the script, remains the stdin
of the bash, preventing it from starting interactively (as that would require my keyboard to be stdin
).
Is there a way to avoid this without going through the extra step of creating a temporary file with the shell script?
You can source
it:
# open a shell
. <(curl http://example.com/hello_scope.sh)
# type commands ...
You could just download this script you (using wget
for example) and source
this script, isn't it ?
script_name="hello_scope.sh"
[[ -f $script_name ]] && rm -rf "$script_name"
wget "http://example.com/$script_name" -O "$script_name" -o /dev/null
&& chmod u+x "$script_name"
&& source "$script_name"
You could use . "$script_name"
instead of source "$script_name"
if you want (.
is POSIX compliant). You could write the previous code in a script and source
it to have interactive shell with the setted variable $HELLO_SCOPE
.
Finally you could remove the eval
line in your remote shell script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With