A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Factorial in Bash page! Here, you'll find the source code for this program as well as a description of how the program works.
#!/bin/bash
number=$1
if [[ -z "$number" ]]
then
echo "Usage: please input a non-negative integer"
exit 1
fi
if ! [[ "$number" =~ ^[0-9]+$ ]]
then
echo "Usage: please input a non-negative integer"
exit 1
fi
value=1
while [ $number -gt 1 ]
do
value=$((value * number))
number=$((number - 1))
done
echo $value
Factorial in Bash was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.