π π’ TuskLang Bash Booleans Guide
π’ TuskLang Bash Booleans Guide
"We don't bow to any king" β Boolean logic, the TuskLang way.
Booleans are the backbone of conditional logic in TuskLang. Whether youβre toggling features, controlling flow, or enforcing security, TuskLangβs boolean system is powerful, flexible, and integrates seamlessly with Bash workflows.
π― What is a Boolean?
A boolean is a value that is eithertrue
or false
. In TuskLang, booleans can be expressed in multiple ways, and are used for:
- Feature flags
- Conditional configuration
- Security checks
- Environment toggles
- System health monitoringπ Syntax Styles
TuskLang supports several boolean representations:INI-style
feature_enabled: true
maintenance_mode: false
JSON-like
{
"debug": true,
"production": false
}
XML-inspired
<settings>
<logging>true</logging>
<readonly>false</readonly>
</settings>
You can also use yes
/no
, on
/off
, and 1
/0
(all are interpreted as booleans):
logging: yes
readonly: off
cache: 1
π Quick Start Example
#!/bin/bash
source tusk-bash.shcat > booleans-quickstart.tsk << 'EOF'
[flags]
debug: true
maintenance: no
feature_x: on
feature_y: 0
EOF
config=$(tusk_parse booleans-quickstart.tsk)
echo "Debug: $(tusk_get "$config" flags.debug)"
echo "Maintenance: $(tusk_get "$config" flags.maintenance)"
echo "Feature X: $(tusk_get "$config" flags.feature_x)"
echo "Feature Y: $(tusk_get "$config" flags.feature_y)"
π Real-World Use Cases
1. Feature Flags
[features]
new_ui: @env("ENABLE_NEW_UI", false)
2. Security Toggles
[security]
require_2fa: @if($environment == "production", true, false)
3. Maintenance Mode
[ops]
maintenance: @env("MAINTENANCE_MODE", false)
4. Conditional Logic in Bash
#!/bin/bash
source tusk-bash.shcat > booleans-logic.tsk << 'EOF'
[ops]
maintenance: @env("MAINTENANCE_MODE", false)
EOF
config=$(tusk_parse booleans-logic.tsk)
if [[ $(tusk_get "$config" ops.maintenance) == "true" ]]; then
echo "Site is in maintenance mode."
else
echo "Site is live!"
fi
π§ Advanced Boolean Logic
Chained Conditions
[deploy]
can_deploy: @if($user_is_admin && !$maintenance, true, false)
Boolean Expressions
[security]
allow_login: @if($account_active && !$locked, true, false)
Environment-Driven Booleans
[env]
prod: @env("APP_ENV", "development") == "production"
π‘οΈ Security & Performance Notes
- Never use booleans for secrets. Use them for toggles, not for storing sensitive data. - Short-circuit logic: TuskLang evaluates boolean expressions efficiently, so use&&
and ||
for performance.
- Environment safety: Always default to false
for security toggles unless explicitly enabled.π Troubleshooting
- Unexpected string values: If you see"yes"
or "no"
as strings, check for missing type conversion or quotes.
- Case sensitivity: TuskLang is case-insensitive for booleans (True
, TRUE
, true
all work).
- Falsy values: 0
, no
, off
, false
are all interpreted as false
.π‘ Best Practices
- Usetrue
/false
for clarity.
- Default to false
for safety.
- Use environment variables for runtime toggles.
- Document all feature flags and toggles.
- Validate boolean values with @validate.type("flag", "bool")
.π Cross-References
- Conditional Logic - Environment Variables - Security Best Practices---
Master boolean logic in TuskLang and control your Bash-powered world with confidence. π’