Hello, what is the safe command to permanently add additional IP to the Ubuntu?

On Ubuntu 22, i have used this one-liner being logged as root and it worked:

read -r -p "Input IP address (including subnet, usually /24) to add as an additional IP to this system:" addip && if [[ "$(ip a|grep -c $addip)" != 0 ]]; then echo "That IP may already be added, see "ip a" output." && exit; fi && apt -qqq install netplan.io && pubip="$(curl -4 ifconfig.co 2>/dev/null)" && for f in "$(grep -Ril $pubip /etc/netplan/)"; do sed -i "s|$pubip/24|$pubip/24\n - $addip|" "$f"; done && netplan apply; echo "Ping new IP:" && ping "$addip"
Is it enough safe? Anyone tried to run it on other Ubuntu?
Any other, better one-liner to achieve the same?