首页 > 解决方案 > 如何将非交互式参数传递到使用“读取”的 bash 文件中?

问题描述

我有以下 shell 脚本:

#! /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

它旨在提示用户,但是我希望在 CI 设置中使用脚本,在该设置中我通过控制台传递参数而不提示。

我目前正在使用echo "<ARG1>\n<ARG2>" | bash run.sh,但我想知道是否有更好的方法来做到这一点。

标签: bashshellcontinuous-integration

解决方案


使用此处的文档

./run.sh <<EOF
arg1
arg2
EOF

推荐阅读