Last active
August 28, 2020 13:32
-
-
Save fakuivan/71080a13207dda173674594e68e165e0 to your computer and use it in GitHub Desktop.
Bash function to get the number of pages in pdf files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pdfpages () { | |
if [[ $# -ne 1 ]]; then | |
echo "$FUNCNAME: expected one argument, got $#" | |
return 1 | |
fi | |
local filename="$1" | |
while read line; do | |
if [[ "$line" =~ ^Pages:" "+([0-9]+)$ ]]; then | |
echo "${BASH_REMATCH[1]}" | |
return 0 | |
fi | |
done < <(pdfinfo -- "$filename") | |
echo "$FUNCNAME: failed to read number of pages using command pdfinfo" | |
return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment