1. Home
  2. /
  3. Bash
  4. /
  5. Counter and Theme Toggle

Counter and Theme Toggle - Bash Typing CST Test

Loading…

Counter and Theme Toggle — Bash Code

Demonstrates a simple counter with theme toggling using Bash variables and console output.

count=0
isDark=0

updateUI() {
	echo "Counter: $count"
	echo "Theme: $( [ $isDark -eq 1 ] && echo 'Dark' || echo 'Light' )"
}

increment() { count=$((count + 1)); updateUI; }
decrement() { count=$((count - 1)); updateUI; }
reset() { count=0; updateUI; }
toggleTheme() { isDark=$((1 - isDark)); updateUI; }

# Simulate actions
updateUI
increment
increment
toggleTheme
decrement
reset

Bash Language Guide

Bash (Bourne Again SHell) is a Unix shell and command language widely used for automation, scripting, DevOps, system administration, and shell-based application workflows. It is the default shell on most Linux systems and offers powerful command-line capabilities.

Primary Use Cases

  • ▸System automation
  • ▸Server maintenance scripts
  • ▸DevOps & CI/CD pipelines
  • ▸File management & text processing
  • ▸Docker and container orchestration
  • ▸Environment setup
  • ▸Scheduling cronjobs

Notable Features

  • ▸Unix pipelines
  • ▸Command substitution
  • ▸Scripting with loops & conditionals
  • ▸Environment variable management
  • ▸Job control & process management

Origin & Creator

Created by Brian Fox at the Free Software Foundation in 1989 as a free replacement for the Bourne Shell (sh).

Industrial Note

Bash excels in environments requiring quick system automation, CI/CD pipelines, container orchestration scripts, server automation, cloud provisioning scripts, and Unix-level glue code that ties together native tools.

More Bash Typing Exercises

Bash Simple CalculatorBash FactorialBash Fibonacci SequenceBash Array Comprehension SimulationBash String ManipulationBash Loop and ConditionalBash Functions with ArgumentsBash Sum of ArrayBash Zip Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher