bash - 如何将非交互式参数传递到使用 "read"的 bash 文件中?

标签 bash shell continuous-integration

我有以下 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 ,但我想知道是否有更好的方法来做到这一点。

最佳答案

使用此处文档

./run.sh <<EOF
arg1
arg2
EOF

关于bash - 如何将非交互式参数传递到使用 "read"的 bash 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69732141/

相关文章:

linux - 有没有办法将时间命令的输出通过管道传输到日志文件中?

bash - 循环输入文件对

Bash 参数替换和扩展一气呵成

linux - 将 stdin _and_ stdout 重定向到管道

iis-7 - 我的 IIS7 网站的元数据库 key 在哪里?

python - Travis CI 默认使用错误的语言

python - 如何解决这个 bash python 交互?

linux - 依次运行多个bash脚本

jenkins - 从 Linux 在 IIS 上发布 Net Core 2.2

Linux 查找脚本结果未附加到输出文本文件