-1

I am trying to delete the security groups by running the command

for i in `aws ec2 describe-security-groups --filters Name=vpc-id,Values="${vpcid}" | grep sg- | sed -E 's/^.*(igw-[a-z0-9]+).*$/\1/'`; do aws ec2 delete-security-group --group-id $i; done

It will delete the custom security group successfully. However, return an error when trying to delete a default security group. I don't want the error to be returned on the terminal, and instead just return nothing.

I have tried to add || true at the end of delete-security-group command, which looks like

for i in `aws ec2 describe-security-groups --filters Name=vpc-id,Values="${vpcid}" | grep sg- | sed -E 's/^.*(igw-[a-z0-9]+).*$/\1/'`; do aws ec2 delete-security-group --group-id $i || true; done

while the error is still printed on the terminal. Any helps

Akira
  • 273
  • 5
  • 15

1 Answers1

-1

using command 2>/dev/null to redirect the error

Akira
  • 273
  • 5
  • 15