我有以下 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/