如何将非交互式参数传递到使用 "read" 的 bash 文件中?
How do I pass in arguments non-interactive into a bash file that uses "read"?
我有以下 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
我有以下 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