Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

Bash one liner if statement is not working

Hi,

 

The following statement cause github action to exit:

[[ "${#TAG_LIST[@]}" -ne 3 ]] && echo "$RELEASE_VERSION is not a valid semantic version" && exit 1

 

The following statement passes

if [[ "${#TAG_LIST[@]}" -ne 3 ]]; then
  echo "$RELEASE_VERSION is not a valid semantic version"
  exit 1
fi

 

Is there any specific reason for that ?

 

Best regards,

 

Jonathan.

2 Replies
Highlighted
GitHub Partner
Message 2 of 3

Re: Bash one liner if statement is not working

Hi @Jojoooo1 , 

When I try the second method, the workflow run also exit. Could you please share your whole workflow yml content here? 

bash.png

Is the result of 

 "${#TAG_LIST[@]}" -ne 3 

 changed in your side? 

Highlighted
Copilot Lvl 2
Message 3 of 3

Re: Bash one liner if statement is not working

Hi @Yanjingzhu 

 

I wrote a bit quickly you will find below the variable details:

 

RELEASE_VERSION=2.3.1
TAG_LIST=(`echo $RELEASE_VERSION | tr '.' ' '`)

# this will pass
if [[ "${#TAG_LIST[@]}" -ne 3 ]]; then echo "$RELEASE_VERSION is not a valid semantic version" exit 1 fi

# this will not pass
[[ "${#TAG_LIST[@]}" -ne 3 ]] && echo "$RELEASE_VERSION is not a valid semantic version" && exit 1