0

Here is part of my linux bash script. I need to input some command line arguments to ./AAAAA executable, but it does not see them. When I wrap them up with <<end .. end, it shows me an "unexpected EOF" error. I've tried to put all input files around .. - didn't help either. I am running out of ideas.

while [ "$month" -le 9 ]
do
            while [ "$day" -le 31 ]
            do
                            "AAAA_15-0$month-$day_text.ff"
                            xargs ./EXECUTABLE <<EOF
                            "AAAA_15-0$month-$day_text.ff"
                            "AAAA_15-0$month-$day_text"
                            "AAAA_15-0$month-$day_text.det"
                            ZZZ.txt
                            XXX.txt
                            CCC.txt
                            VVV.txt
                            BBB.txt
                            EOF
                            mv "AAAA_15-0$month-$day_text"*"."* "15-0$month-$day_text"
                            day=`expr $day + 1`
            done
            day=`expr $month + 1`

done

2
  • We don't really know how your ./AAAAA executable works, so it's hard to say. Does it have any documentation ? Or do you have its source code ? Commented Dec 16, 2016 at 17:01
  • What you have is in fact not an argument, it's data redirected to the stdin (standard input stream). So your executable should read it from the stdin stream. Commented Dec 16, 2016 at 17:05

2 Answers 2

1

Use xargs:

xargs ./AAAA <<EOF
XXXX.ff
XXXX.det
CCCC.txt
BBBB.txt
NNNN.txt
MMMM.txt
LLLL.txt
EOF
Sign up to request clarification or add additional context in comments.

9 Comments

The problem is that my filenames are prone to change, since they are inside a cycle. I just simplified it in my question....
Your question should contain enough information to understand your problem. Can you edit it?
My bad. I put all script there now. EOF sollution gives me here-document at line 20 delimited by end-of-file.
About your problem, the ending EOF needs to be placed at the very beginning of the line (meaning position 0, even if that might look odd for you)
Thanks for the pointer on EOF at comment#5. If auto-indenting is enabled, this would mean that an error would creep in accidentally which is very difficult to detect.
|
0

When you use <<EOF, the EOF has to be at the beginning of the line, it won't be found if it's indented.

while [ "$month" -le 9 ]
do
    while [ "$day" -le 31 ]
    do
        "AAAA_15-0$month-$day_text.ff"
        xargs ./EXECUTABLE <<EOF
        "AAAA_15-0$month-$day_text.ff"
        "AAAA_15-0$month-$day_text"
        "AAAA_15-0$month-$day_text.det"
        ZZZ.txt
        XXX.txt
        CCC.txt
        VVV.txt
        BBB.txt
EOF
        mv "AAAA_15-0$month-$day_text"*"."* "15-0$month-$day_text"
        day=`expr $day + 1`
    done
    day=`expr $month + 1`
done

You can instead use <<-EOF. This allows it to be indented, but the indentation must be Tab characters, not spaces.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.