I often execute raw versions of remote Bash scripts in GitHub with this pattern:
wget -O - https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> | bash
Generally I can do it without problems but since I have added the following code to a certain script I get an endless loop of echo
(it often occurs even if I just copy-paste it from GitHub to the terminal and execute directly):
while true; do
read -p "Example question: Do you wish to edit the PHP file now?" yn
case $yn in
[Yy]* ) nano PROJECT/PHP_FILE; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done
I can at least partly solve the problem with something like:
cd ACTION_DIRECTORY
wget https://raw.githubusercontent.com/<username>/<project>/<branch>/<path>/<file> &&
source FILENAME &&
rm FILENAME
Which indicates that the | bash
piping at least worsens the problem because the problem always happens with it.
Why would echo "Please answer yes or no."
happen "endlessly"? (which I stop it with CTRLC+C)
Do you find any problem either in the single lined execution command and/or in the while true; do case esac done
?
source
is good? Would you change anything there to make it more friendly with the loop andcase esac
? Thanks anyway, – variable_expander Mar 20 '21 at 11:45source
realizes a good idea (download first, run later) with some potential flaws: (1) unquoted${HOME}
; (2)&&
aftersource …
makesrm
depend on what the script does (this may or may not be what you want). // In general it's better to run a script (i.e. not to source), unless you know you need to source.bash FILENAME
runs it by a separatebash
../FILENAME
runs it according to the shebang (if present), butFILENAME
needs to be executable. – Kamil Maciorowski Mar 20 '21 at 12:36