This page describes a basic Linux shell script (WECM100/b004.sh) designed to demonstrate variable usage for embedded beginners. It was executed within a Windows Subsystem for Linux (WSL) environment on Windows 11.
//$ uname -a: Linux asus-oda 5.15.167.4-microsoft-standard-WSL2 1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux //$ pwd >> /home/miura //$ whoami >> miura
$ cd ./WECM100 $ nano b004.sh # Edit shell script $ chmod +x b004.sh # Make script executable $ ./b004.sh # Execute script
#!/bin/bash
x=10
y=20
# Join characters ------------------
joi=$x$y
echo "{\"x\":$x,\"y\":$y,\"joi\":$joi}"
# Add integers ------------------
add=$((x+y))
echo "{\"x\":$x,\"y\":$y,\"add\":$add}"
{"x":10,"y":20,"joi":1020}
{"x":10,"y":20,"add":30}
This script demonstrates two fundamental operations with variables in a Bash shell script:
x and y are concatenated (joined) to form the string 1020 and stored in the joi variable.x and y are added using the arithmetic expansion $((x+y)), resulting in 30, which is stored in the add variable.The script then outputs the values of x, y, joi, and add in JSON-like format for easy parsing or display.
This script is a simple introduction to variable manipulation in Bash, which is crucial for automating tasks and creating more complex scripts.