You are not logged in.
Hello Everyone,
If have the following If statement in a script:
if [[ $1 =~ ^[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}\:[A-Fa-f0-9]{4,4}$ ]]; then
Is there any way to break this statement into multiple lines? I tried entering a \ after a portion of the statement and then pressing Enter to add a newline but it did not work.
thriftyb
Last edited by thriftyb (2015-04-03 21:44:13)
Offline
WTF. Use grep -P or something. Or better, tell us what you're trying to do.
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
The backslashes should work: http://stackoverflow.com/questions/1859 … -statement
as the answer points out, make sure you have no whitespace after the backslash.
"We may say most aptly, that the Analytical Engine weaves algebraical patterns just as the Jacquard-loom weaves flowers and leaves." - Ada Lovelace
Offline
You could at least do
if [[ $1 =~ ^([A-Fa-f0-9]{4,4}\:){7,7}[A-Fa-f0-9]{4,4}$ ]]; then
and then maybe put the duplicate pattern in a variable with a descriptive name:
hextet="[A-Fa-f0-9]{4,4}"
if [[ $1 =~ ^($hextet\:){7,7}$hextet$ ]]; then
Offline
@Alad: This statement tests for a valid IPv6, testing each part of the entered address to make sure it is a group of four hexadecimal digits with each group being separated by a colon.
@Rayman: Cool, I think that your method will work.
thriftyb
Offline
if grep -xP '(([A-Fa-f0-9]{4}):){7}(?2)' <<< "$1"; then
http://www.regular-expressions.info/subroutine.html
Last edited by Alad (2015-04-03 00:01:49)
Mods are just community members who have the occasionally necessary option to move threads around and edit posts. -- Trilby
Offline
if grep -xP '(([A-Fa-f0-9]{4}):){7}(?2)' <<< "$1"; then
That works too. I didn't know that grep could be used that way. Thanks.
Offline
That's what grep is for. Think what one would do in an old shell which has no builtin regex operator.
aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies
Offline