I have a simple Bash script:
#!/usr/bin/env bash read X echo "X=$X" When I execute it with ./myscript.sh it works. But when I execute it with cat myscript.sh | bash it actually puts echo "X=$X" into $X.
So this script prints Hello World executed with cat myscript.sh | bash:
#!/usr/bin/env bash read X hello world echo "$X" - What's the benefit of executing a script with
cat myscript.sh | bash? Why doesn't do it the same things as if I execute it with./myscript.sh? - How can I avoid Bash to execute line by line but execute all lines after the STDIN reached the end?
bash ./myscript.sh./myscript.shcurland then pipe it to bash to avoid a creation of a temp file, like Composer does it with PHP (getcomposer.org/download). But if this way doesn't work I also need to do it with PHP or with a temp file.readstdinredirected to/dev/tty, as it was just NOW answered by Charles...