If user [condition] then [output] else [output]

I want a command that gives output1 if User1 uses it and if any other user uses it output2 should come

sry for my english rn xd

$(eval "$(user)"=="User_Allowed_To_Use"?"Message_For_User":"Message_For_Others")

Expanding on this, what if it were a list of users (let’s say 2) ?

Would that be

$(eval "$(user)"=="User_Allowed_To_Use"||"User2_Allowed_To_Use"?"Message_For_User":"Message_For_Others")

?

Hey @zoeballz!

No, such test will always produce a truthy output, so you’ll always have Message_For_User as output, and never Message_For_Others.

For the code to work as expected you have two solutions:

  • the basic one, which quickly gets cumbersome:

    $(eval '$(user)' === 'User_Allowed_To_Use' || '$(user)' === 'User2_Allowed_To_Use' ? 'Message_For_User' : 'Message_For_Others';)
    
  • the better one, because it’s just cleaner code with no repetition:

    $(eval ['User_Allowed_To_Use', 'User2_Allowed_To_Use'].includes('$(user)') ? 'Message_For_User' : 'Message_For_Others';)
    

AH ok :slight_smile:

Thanks very much :slight_smile: (Not used JS much) !!

Zoe

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.