Coding⏱️ 2 min read📅 2026-05-31

How to Fix: "unary operator expected" error in Bash if condition

Fix unary operator expected error in Bash if condition by removing quotes around variable values.

Quick Answer: Remove quotes around $aug1 and $operation variables.

The error "unary operator expected" in Bash occurs when the compiler expects a unary operator (like +, -, *, /) but finds something else. In this case, it's likely due to the single quotes around the string values in the conditionals.

⚠️ Common Causes

  • Using single quotes around string values in conditionals.

🔧 Proven Troubleshooting Steps

Method 1: Remove Single Quotes

  1. Step 1: Identify and remove single quotes from string values in the conditionals.

Method 2: Use Double Quotes

  1. Step 1: Surround string values with double quotes instead of single quotes.

✨ Wrapping Up

By following these steps, you should be able to resolve the "unary operator expected" error and get your script running smoothly.

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions