Reputation: 475
Hi I am getting error in this line below
BOOTPROTO="dhcp"
TEST=$([[ "$BOOTPROTO" =~ (static|none|bootp|dhcp)$ ]] ; echo $?)
error I am getting is below
-bash: command substitution: line 1: unexpected argument `(' to conditional binary operator
-bash: command substitution: line 1: syntax error near `(s'
-bash: command substitution: line 1: `[[ "$BOOTPROTO" =~ (static|none|bootp|dhcp)$ ]] ; echo $?'
I tried to run it manually but could not solve it
Upvotes: 2
Views: 69
Reputation: 22217
Why not simply
[[ "$BOOTPROTO" =~ (static|none|bootp|dhcp)$ ]]
TEST=$?
?
Upvotes: 0
Reputation: 2509
Wrap your regex in quotes:
BOOTPROTO="dhcp"
TEST=$([[ "$BOOTPROTO" =~ "(static|none|bootp|dhcp)$" ]] ; echo $?)
echo "$TEST"
Or if you are using Bash >= 3.2, then escape the parentheses (as Eric mentioned in the comments.)
TEST=$([[ "$BOOTPROTO" =~ \(static|none|bootp|dhcp\)$ ]] ; echo $?)
Output:
1
Upvotes: 3