Score:0

How to extract part of var with substring substition if exists

cn flag

I need to extract IP and PORT (if exists) from address. I currently use following and it works if address has :port, but if it doesn't PORT variable becomes also IP. How to have PORT to be null if no port specified

#ADDR=1.2.3.4:12345
ADDR=1.2.3.4
IP=${ADDR%:*}
PORT=${ADDR#*:}
Score:0
cn flag

So answer was already given in the previous question by steeldriver

https://askubuntu.com/a/1458499/1177212

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.