2016-07-05 131 views
1

我試圖根據我在某些頁面編號上找到的字符串將ptftk分割爲tempfile.pdf。那些pagenumbers在tempfile中。我在這裏用這些變量做錯了什麼?

n=0 
prefix1="startpoint" 
prefix2="stoppoint" 
while read p; do 
    echo $p > temp 
    `cat temp` = prefix1$n 
    echo $((p-1)) > temp 
    `cat temp` = prefix2$n 
    n=$((n+1)); 
done < tempfile 

pdftk tempfile.pdf cat $startpoint0-$stoppoint1 output $1/01-0.pdf 
pdftk tempfile.pdf cat $startpoint1-$stoppoint2 output $1/02-0.pdf 
pdftk tempfile.pdf cat $startpoint2-end output $1/03-0.pdf 

出於某種原因,我得到這樣的錯誤:

/usr/local/bin/skapa_digital_akt: rad 16: 1: kommandot finns inte 
/usr/local/bin/skapa_digital_akt: rad 18: 0: kommandot finns inte 
/usr/local/bin/skapa_digital_akt: rad 16: 6: kommandot finns inte 
/usr/local/bin/skapa_digital_akt: rad 18: 5: kommandot finns inte 
/usr/local/bin/skapa_digital_akt: rad 16: 13: kommandot finns inte 
/usr/local/bin/skapa_digital_akt: rad 18: 12: kommandot finns inte 
Error: Unexpected range end; expected a page 
    number or legal keyword, here: 
    Exiting. 
Errors encountered. No output created. 
Done. Input errors, so no output created. 
Error: Unexpected range end; expected a page 
    number or legal keyword, here: 
    Exiting. 
Errors encountered. No output created. 
Done. Input errors, so no output created. 
Error: Input page numbers include 0 (zero) 
    The first PDF page is 1 (one) 
    Exiting. 
Errors encountered. No output created. 
Done. Input errors, so no output created. 

顯然變量起始點/ stoppoint設置錯誤。任何人都可以幫助我?

非常感謝!

/保羅

回答

1

什麼是

`cat temp` = prefix1$n 

該怎麼辦?您應該知道:它從temp中讀取命令行並執行它。

如果臨時包含1(和n== 0)一條線,那麼執行的命令是:

1 = prefix10 

你經常可以幫助自己對劇本的頂部插入set -x或調用它調試腳本使用sh -x yourscript.sh

0

這工作:

n=0 
while read p; do 
    echo $p > tempA$n 
    echo $((p-1)) > tempB$n 
    n=$((n+1)); 
done < tempfile 

startpoint0=$(cat tempA0) 
stoppoint1=$(cat tempB1) 
startpoint1=$(cat tempA1) 
stoppoint2=$(cat tempB2) 
startpoint2=$(cat tempA2) 


pdftk tempfile.pdf cat $startpoint0-$stoppoint1 output $1/01-0.pdf 
pdftk tempfile.pdf cat $startpoint1-$stoppoint2 output $1/02-0.pdf 
pdftk tempfile.pdf cat $startpoint2-end output $1/03-0.pdf 
相關問題