For my current project I need to validate responses. The requests will be send from multiple different shell scripts and should be controlled from another script. I'd never targeted a .sh
with a .sh
before, so let's try some FizzBuzz first.
Fizz.sh
#!/bin/bash
if [ $# -eq 0 ]
then
echo "This FizzBuzz is interactive. Please provide the upper limit."
echo "Usage : $0 limit"
exit 1
fi
for i in `seq $1`
do
echo `source ./buzz.sh $i`
done
Buzz.sh
#!/bin/bash
([ $(($1%15)) -eq 0 ] && echo 'FizzBuzz') ||
([ $(($1%5)) -eq 0 ] && echo 'Buzz') ||
([ $(($1%3)) -eq 0 ] && echo 'Fizz') ||
echo $1;
- Is it idiomatic?
- Is this the best way to hand all output from Buzz to Fizz?
The goal is to learn decent BASH. The FizzBuzz has no need for optimization, it's mostly about style, how data should be passed from script to script and whether I followed BASH-practices or not.