linux script variables from different files and using pdftk

I'm new at scripting but giving it a try and encountering some problem I can't seem to fix.

What I'm trying to do is to cat different pdf files using pdftk , the files I'd like to cat are being fed from a different program which is able to trigger a script file, but unable to send parameters with it. Therefore I create two .txt files one with a single setting and one with a file name. The setting file has to tell my script if it should create a new file or not and the filename should tell my script what file to cat into the big pdf file.

Both the setting and filename files are read into variables and by using echo I can see that the values of these variables are correct, I can't however use them for some reason I can't figure out.

This is my script:

#!/bin/bash

#on Date       Who   Call Remarks
# ------- ---------- --- ------ -------------------------------------------- 
# 1.0     28-07-2014 AAS ------ New script to combine pdf files.
#
# ==========================================================================
#
#Changelog:
#
#
#
# Locvar:

file=$(cat "/home/scanning/finloon/concatfile.txt")
setting=$(cat "/home/scanning/finloon/concatsetting.txt")

echo $file
echo $setting

removefile()
{
    echo "remove combine.pdf"
    rm -f -r /home/scanning/finloon/combine.pdf
    rm -f -r /home/scanning/finloon/workfile.pdf
}

makefirst()
{
    echo "make first combine.pdf"
    pdftk /home/scanning/janssen/linked/44/$file cat output combine.pdf
}

copyfile()
{
    echo "copy to workfile.pdf"
    cp /home/scanning/finloon/combine.pdf /home/scanning/finloon/workfile.pdf
}

combinefile()
{
    echo "combine files"
    pdftk /home/scanning/finloon/workfile.pdf /home/scanning/janssen/linked/44/$file     cat output combine.pdf
}

if [ "$setting" == "yes" ];
        then
    removefile
    makefirst $file
else
    copyfile
    combinefile $file
fi

exit

the content of concatsetting.txt = yes (unix file, contains no spaces)

the content of concatfile.txt = 1.pdf (unix file, contains no spaces)

Now when I run My script I's expect it to do the first commands in the if statement due to the value of $setting being yes but it won't. I suspect it has something to do with the string I use as a variable because when I change the if-statement to use a variable $1 and I start the script by concatcmr.sh yes it works but then I'm also unable to use the filename stored in the file variable. here I seem to have the same problem because if I change that variable to $2 and start my script as concatcmr.sh yes 1.pdf everything works.

Now if I run the script this is the output I get:

$ concatcmr.sh

1.pdf

yes

copy to workfile.pdf

cp: cannot stat `/home/scanning/finloon/combine.pdf': No such file or directory

combine files

Error: Unable to find file.

Error: Failed to open PDF file:

/home/scanning/finloon/workfile.pdf

Error: Unable to find file.

Error: Failed to open PDF file:

Errors encountered. No output created.

Done. Input errors, so no output created.

$

sllthough the content of $setting is yes the if statement doesn't recognise this and skips to the else statement. I can't figure out why, must be something stupid but I just can't find It.

Thanks in advance for your help!

cheers.

链接地址: http://www.djcxy.com/p/46958.html

上一篇: 从另一部分构建PDF文件

下一篇: 来自不同文件和使用pdftk的linux脚本变量