Skip to content

Instantly share code, notes, and snippets.

@Da-Juan
Created March 30, 2018 08:29
Show Gist options
  • Save Da-Juan/45f68b4edf918d74bb0c6b14afb2ba53 to your computer and use it in GitHub Desktop.
Save Da-Juan/45f68b4edf918d74bb0c6b14afb2ba53 to your computer and use it in GitHub Desktop.
Order page numbers to print in booklet
#!/bin/bash
n=$1
j=0
pages=""
for i in $(seq 1 $(( n / 2))); do
if [ $((i%2)) -ne 0 ]; then
if [[ $pages != '' ]]; then
pages=$pages','
fi
pages=$pages$(( n - j ))','$i
else
if [[ $pages != '' ]]; then
pages=$pages','
fi
pages=$pages$i','$(( n - j ))
fi
(( j++ ))
done
echo "$pages"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment