The programs of the lessons
120 short programs in BASIC, Pascal, Go and Bash, 30 in each language. Each one ran on a QNAP NAS.
All 120 programs
The archive has each program, the commands that ran it (.session), what the terminal showed (.out), the sample files and the script that runs the programs again. Where a number or a date changes from run to run, a .vary file says which.
Check them yourself
Unpack the archive in a folder of a share and run the script on a NAS with TurboShell. It runs each program in a folder of its own and compares what it prints with the kept output.
tar xzf turboshell-lessons.tar.gz
cd turboshell-lessons
./tools/run-examples.sh basic pascal bashThe Go programs first become files in go-bin, with Go on the path: run bash tools/build-go.sh in Bucket & Code, then ./tools/run-examples.sh go on the NAS.
BASIC
01-hello.yabPrint a line02-print.yabSeveral parts on a line03-variables.yabKeep a value in a variable04-numbers.yabCount with numbers05-text.yabCut and join text06-input.yabAsk the user07-if.yabDecide with if08-conditions.yabJoin conditions09-switch.yabChoose from a menu10-loops.yabRepeat with loops11-loop-control.yabLeave or skip a turn12-nested-loops.yabA loop in a loop13-arrays.yabMany values, one name14-split.yabCut a line into fields15-sub.yabName a block of lines16-functions.yabGive a value back17-arguments.yabRead the command line18-exit-codes.yabReport success or failure19-files.yabWrite and read a file20-file-errors.yabHandle a missing file21-csv.yabRead a table22-calculator.yabBuild a calculator23-sort.yabSort values24-word-count.yabCount words in a file25-run-command.yabRun a command26-free-space.yabRead df27-largest-files.yabFind the largest files28-log-summary.yabSummarise a log29-notepad.yabBuild a notepad30-report.yabFinish a tool
Pascal
01-hello.pasCompile a program02-write.pasWrite in columns03-variables.pasDeclare variables04-numbers.pasCount with numbers05-text.pasWork with text06-input.pasAsk the user07-if.pasDecide with if08-conditions.pasJoin conditions09-case.pasChoose with case10-loops.pasRepeat with loops11-check-input.pasCheck what the user typed12-table.pasA loop in a loop13-arrays.pasKeep many values14-dynamic-arrays.pasLet an array grow15-procedures.pasName a block of lines16-functions.pasGive a value back17-records.pasJoin fields into a record18-enums-sets.pasUse your own values19-files.pasWrite and read a file20-exceptions.pasHandle an error21-arguments.pasRead the command line22-units.pasSplit a program into units23-calculator.pasBuild a calculator24-string-lists.pasKeep lines in a list25-classes.pasWrite a class26-dated-backup.pasCopy a file with a date27-largest-files.pasWalk through folders28-free-space.pasAsk the system for free space29-notepad.pasBuild a notepad30-report.pasFinish a tool
Go
01-hello.goBuild a program02-variables.goDeclare variables03-printf.goPrint in columns04-numbers.goCount with numbers05-text.goWork with text06-input.goAsk the user07-if.goDecide with if08-switch.goChoose with switch09-loops.goRepeat with for10-functions.goWrite functions11-errors.goHandle errors12-slices.goKeep values in a slice13-maps.goCount with a map14-structs.goJoin fields into a struct15-methods.goGive a struct methods16-interfaces.goUse an interface17-pointers.goPass an address18-flags.goRead options19-files.goWrite and read a file20-json.goRead and write JSON21-calculator.goBuild a calculator22-word-count.goCount words from standard input23-dated-backup.goCopy a file with a date24-largest-files.goWalk through folders25-free-space.goAsk the system for free space26-run-command.goRun a command27-goroutines.goDo work side by side28-log-summary.goSummarise a log29-notepad.goBuild a notepad30-report.goFinish a tool
Bash
01-hello.shRun a script02-variables.shKeep a value in a variable03-arguments.shRead the command line04-read.shAsk the user05-exit-codes.shUse exit codes06-if.shDecide with if07-tests.shTest files and text08-case.shChoose with case09-loops.shRepeat with loops10-while-read.shRead a file line by line11-arithmetic.shCount with numbers12-functions.shWrite functions13-return.shReturn a code14-arrays.shKeep many values15-maps.shCount with names16-text.shCut text without other commands17-pipes.shJoin commands18-redirect.shSteer the output19-files.shWrite and read a file20-strict.shStop at the first error21-trap.shClean up at the end22-options.shRead options23-calculator.shBuild a calculator24-free-space.shRead df25-largest-files.shFind the largest files26-log-summary.shSummarise a log27-dated-backup.shBack up a folder with a date28-disk-health.shRead smartctl29-notepad.shBuild a notepad30-report.shFinish a tool
The sample files
Some programs read these files. Copy each one into the folder of your lessons.
nas.log
2027-01-04 02:00:01 INFO backup started
2027-01-04 02:14:37 INFO backup finished
2027-01-04 08:31:12 WARN disk 3 temperature 51
2027-01-04 09:02:44 ERROR share Documents is full
2027-01-05 02:00:01 INFO backup started
2027-01-05 02:03:10 ERROR backup stopped: no space
2027-01-05 02:03:10 WARN free space below 5 percent
2027-01-05 11:47:29 INFO admin signed in
2027-01-06 02:00:01 INFO backup started
2027-01-06 02:13:58 INFO backup finished
2027-01-06 14:20:05 WARN disk 3 temperature 53
2027-01-06 18:09:33 ERROR disk 3 read errordisks.csv
slot,model,size_gb,temp_c
1,Example HDD A,8000,38
2,Example HDD A,8000,39
3,Example HDD B,12000,53
4,Example SSD C,1000,44smartctl.txt
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 8
9 Power_On_Hours 0x0032 071 071 000 Old_age Always - 26280
12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 64
194 Temperature_Celsius 0x0022 112 098 000 Old_age Always - 38
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x0032 200 200 000 Old_age Always - 2df.txt
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/data1 7751370240 5813527680 1937842560 75% /volume/data
/dev/data2 3875685120 3604387161 271297959 93% /volume/media
/dev/fast1 976762584 195352516 781410068 20% /volume/fastconfig.ini
[report]
title=Morning check
limit=90
[backup]
folder=backups
keep=3words.txt
The NAS keeps files.
The files live on disks.
Disks fail, so keep a copy of the files.The folder photos has six files of fixed sizes. These commands make it:
mkdir -p photos
for f in 4200:beach.jpg 900:cat.jpg 15800:wedding.mov 2600:garden.jpg 7300:trip.mp4 120:notes.txt; do
head -c "${f%%:*}" /dev/zero > "photos/${f#*:}"
done