Description: Unlock the power of shell scripts with this comprehensive guide to using sh, bash, and source commands to execute your code. Discover how to pass parameters to your scripts, process substitutions, and handle input from both files and web requests. Whether you're a seasoned developer or just getting started with shell scripting, this article will help you take your skills to the next level.
We could execute command into bash in different form from stdin, file and web request.
bash file-script.sh
# or
sh file-script.sh
# or
source file-script.sh
bash file-script.sh {param}
# or
sh file-script.sh {param}
# or
source file-script.sh {param}
cat file-script.sh | bash
# or
cat file-script.sh | sh
# source doesn't support pipeline
bash <(cat file-script.sh)
# or
sh <(cat file-script.sh)
# or
source <(ca file-script.sh)
bash <(cat file-script.sh) {parameter}
# or
sh <(cat file-script.sh) {parameter}
# or
source <(ca file-script.sh) {parameter}
We could also pull a shell script from web request.
bash <(curl {url})
# or
sh <(curl {url})
# or
source <(curl {url})