Junior — Middle
How to specify a condition in Bash using a one-liner command?
sobes.tech AI
Answer from AI
In Bash, a one-line condition can be written using the if ...; then ...; else ...; fi construct. For example:
if [ "$VAR" = "value" ]; then echo "Matches"; else echo "Does not match"; fi
You can also use a shortened syntax with the && and || commands:
[ "$VAR" = "value" ] && echo "Matches" || echo "Does not match"
The first option is more readable and versatile, while the second is compact for simple conditions.