29 lines
567 B
Shell
Executable file
29 lines
567 B
Shell
Executable file
#!/bin/bash
|
|
|
|
check_is_number() {
|
|
if [[ ! $1 =~ ^[0-9]+$ ]]; then
|
|
exit 1
|
|
fi
|
|
exit 0
|
|
}
|
|
|
|
# Check first argument is a number
|
|
$(check_is_number $1)
|
|
if [ "$?" -gt 0 ]; then
|
|
echo "First page number: $1 is not a number."
|
|
exit 1
|
|
fi
|
|
|
|
# Check second argument is a number
|
|
$(check_is_number $2)
|
|
if [ "$?" -gt 0 ]; then
|
|
echo "Last page number: $2 is not a number."
|
|
exit 1
|
|
fi
|
|
|
|
if [ ! -f $3 ]; then
|
|
echo "File \"$3\" doesn't exists."
|
|
exit 1
|
|
fi
|
|
|
|
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -dFirstPage=$1 -dLastPage=$2 -sOutputFile=$4 $3
|