Introduction
In Bash, if statements can be used with multiple conditions. This challenge demonstrates how to define multiple conditions in an if statement using AND logic.
In Bash, if statements can be used with multiple conditions. This challenge demonstrates how to define multiple conditions in an if statement using AND logic.
Create a Bash script named if_with_AND.sh that prompts the user to enter a username and password. The script will then compare the entered values with the strings "admin" and "secret" respectively. If both values match, the output will be "valid user". Otherwise, the output will be "invalid user".
~/project/if_with_AND.sh
;To run the script, use the following command:
labex:project/ $ bash if_with_AND.sh
Output:
Enter username
admin
Enter password
secret
valid user
labex:project/ $
This challenge demonstrated how to use the AND operator in an if statement in Bash. By comparing two or more conditions using the && operator, we can create more complex logical statements in our scripts.