NASutils Knowledge BaseUnofficialPolski

Bash · lesson 4 of 30 · First stepsAsk the user

read -rp asks and keeps the answer. With two names the first gets the first word and the second gets the rest.

Programming on the NAS › Bash in 30 lessons

04-read.sh Download 04-read.sh

#!/usr/app/TurboShell/bin/bash
read -rp "Your name: " name
read -rp "Disks and TB in each: " disks size
echo "Hello, $name"
if [[ ! $disks =~ ^[1-9][0-9]*$ || ! $size =~ ^[1-9][0-9]*$ ]]; then
  echo "Type two whole numbers from 1"
  exit 1
fi
echo "Together the disks have $((disks * size)) TB"

Terminal

$ bash 04-read.sh
Your name: Ann Example
Disks and TB in each: 4 8
Hello, Ann Example
Together the disks have 32 TB

Exercise

Ask for a folder and say whether it exists.