1

I am trying to use a variable as an operator inside an if test.

if [[ $action = "active" ]];then operator="-le" fi if [[ $Apps $operator 100 ]];then echo "No of apps $Apps" fi 

I am getting syntax error near `

1
  • Near what? Near `? There's no backtick in your code. Commented Jan 3, 2020 at 18:31

2 Answers 2

2

You can switch to [, which won't seen its arguments until after the shell has expanded all the parameters. [[ has to be fully parsed before $operator is expanded, and it needs to see an actual operator.

if [ "$Apps" "$operator" 100 ]; then echo "No of apps $Apps" fi 
Sign up to request clarification or add additional context in comments.

Comments

0

Have you try nested if operators?

if [ "$action" = "active" ] then if [ "$Apps" -eq 100 ] .... 

1 Comment

Thanks for response .. Because of other code.. i have to do it seperately .. But single bracket worked

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.