在bash脚本中,我希望获得响应,并将其小写,以预测和避免错误。
但是,当我将response转换为小写时,似乎无法将该更改存储在变量中。
如何更新输入字符串的情况并进行存储,以便以后进行比较?
#!/usr/bin/env bash -e
echo "To reset cluster on existing EKS cluster, we must first destroy the existing cluster."
read -p "Do you want to auto-approve the terraform destroy (y/n): " response
response="$response" | tr '[:upper:]' '[:lower:]'
echo $response
if [ $response = 'y' ]; then
echo "Destroy is auto-approved."
else
echo "Destroy is not auto-approved"
fi发布于 2022-06-07 06:18:34
不需要为此任务创建子进程。简单地做一个
response=${response,,?},,运算符将由glob模式?匹配的每个字符转换为大写。
更新:正如肖恩所指出的,并且根据手册页(它说:如果省略了pattern,它被当作一个与每个字符匹配的?),您可以省略问号,只做一个:
response=${response,,}https://stackoverflow.com/questions/72526472
复制相似问题