I am trying to provide opts to a bash script when piping the script contents to bash for execution.
#!/bin/bash
SETUP_PACKAGES=""
while getopts ":u:" opt; do
case $opt in
p)
if [[ "$OPTARG" =~ "mysql" ]] ; then SETUP_PACKAGES="$SETUP_PACKAGES mysql-client libmysqlclient-dev"; fi
;;
# other parts omitted...
esac
done
Executing the script in a shell like ./script.sh -p mysql works. The aim is to store the script in a repository so I tried curl -L example.com/my/script | bash -p mysql. This however throws /usr/bin/mysql: /usr/bin/mysql: cannot execute binary file.
What do I need to do to achieve my goal?
You need
-soption for bash in order to set positional parameters for an interactive shell: