-
-
Save d630/80c9e76a04f9ff42ca8eb54f37d785ee to your computer and use it in GitHub Desktop.
bash: how to get port number from the "port: 5432," line (no quotes)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nr. 1 | |
p='port: 5432,' | |
echo ${p//[!0-9]/} | |
# Nr. 2 | |
IFS=':, ' read -r _ p <<< "port: 5432," | |
# Nr. 3 | |
awk -F[,:] '{print $2+0}' <<< "port: 5432," | |
# Nr. 4 | |
p='port: 5432,' | |
[[ $p =~ (port:)( )?*([0-9]?*), ]] && echo ${BASH_REMATCH[3]} | |
# Nr. 5 | |
p='port: 5432,' | |
printf '%d\r%d\n' ${p} 2>/dev/null | |
# Nr. 6 | |
p='port: 5432,'; | |
: $p; echo ${_%,} | |
# Nr. 7 | |
p='port: 5432,' | |
( set -- ${p%,}; echo ${2} ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment