How do I pass in arguments non-interactive into a bash file that uses "read"?

Viewed 103

I have the following shell script:

#! /bin/bash

. shell_functions/commonShellFunctions.sh
. shell_functions/settings.sh
_valid_url=1

echo "Welcome to HATS Accessibility Testing Tool!"
echo "We recommend using Chrome browser for the best experience."
echo "What would you like to scan today?"

options=("sitemap file containing links" "website")

select opt in "${options[@]}"
do
    case $opt in

        "sitemap file containing links")

            scanType="sitemap"
            crawler=crawlSitemap
            prompt_message="Please enter URL to sitemap: "
            break;;

        "website")

            prompt_website
            break;;

        "exit")
            exit;;

        *)
            echo "Invalid option $REPLY";;

    esac

done

read -p "$prompt_message" page


echo $page

It was meant to prompt the user, however I wish to use the script in a CI setting where I pass the arguments through the console without prompting.

I'm currently using echo "<ARG1>\n<ARG2>" | bash run.sh, but I'm wondering if there's a better way to do this.

1 Answers

Use a here-document

./run.sh <<EOF
arg1
arg2
EOF
Related