[Update]Please note that this is a simplified code for this post in order to satisfy minimal reproducible example. There will more functions in the script.
I have a Bash script on a Github repo:
#!/usr/bin/env bash
fn_test1() {
echo "starting ..."
read -rp "Do you want to continue? yes/y or no/n " PANS
ans=$(echo "$PANS" | cut -c 1-1 | tr "[:lower:]" "[:upper:]")
if [[ "$ans" = "Y" ]]; then
echo "confirmed 1."
fi
echo "done"
}
fn_main() {
if [ $# -eq 1 ]; then
case $1 in
"test")
fn_test1
;;
esac
else
echo "Something wrong."
exit 1
fi
}
fn_main "$@"
I want to call the test
function from this script like this, but it doesn't work:
bash -c "$(curl -s https://raw.githubusercontent.com/shinokada/awesome/main/test; test)"
The output is:
Something wrong.
How can I call a function in a bash script? Is it possible?