【发布时间】:2022-10-21 14:52:29
【问题描述】:
Input = ./q4.sh https://cdn.eso.org/images/thumb700x/eso1723a.jpg
echo $1 | -Eiq '^https?://' 2> /dev/null || echo 'Ce script supporte seulement les URLs commencant par https:// ou http://' && exit 1
即使我的参数 1 有 http:// 或 https://,输出也总是跳转到最后一个 || echo 'Ce script supporte seulement les URLs commencant par https:// ou http://'。
【问题讨论】:
-
我不能使用 if/fi 或任何其他命令然后 echo/grep 我必须将我的 stderr 重定向到 /dev/null
-
不需要 2 个单独的 grep。只需一个简单的正则表达式就足够了:
https?:// -
像这样 ?回声 $1 | grep -i "https?://" $1 2> /dev/null || echo 'Ce script supporte seulement les URLs commencant par https:// ou http://' && exit 1 因为它一直把我送到最后 ||即使我的 arg1 有 https:// 或 http:// 的选项