Move under www to ease rsync
This commit is contained in:
34
www/eps/hpr2719/hpr2719_bash17_ex1.sh
Executable file
34
www/eps/hpr2719/hpr2719_bash17_ex1.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Example 1 for Bash Tips show 17: Negative indices
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#
|
||||
# Seed the Fibonacci sequence in an indexed array
|
||||
#
|
||||
declare -a fib=(0 1 1)
|
||||
|
||||
#
|
||||
# Populate the rest up to (and including) the 20th element
|
||||
#
|
||||
for ((i = 3; i <= 20; i++)); do
|
||||
fib[$i]=$((fib[i-2]+fib[i-1]))
|
||||
done
|
||||
|
||||
#
|
||||
# Show the whole array
|
||||
#
|
||||
echo "Fibonacci sequence"
|
||||
echo "${fib[*]}"
|
||||
echo
|
||||
|
||||
#
|
||||
# Print a few elements working backwards
|
||||
#
|
||||
for i in {-1..-4}; do
|
||||
echo "fib[$i] = ${fib[$i]}"
|
||||
done
|
||||
|
||||
exit
|
||||
|
||||
Reference in New Issue
Block a user