Bash Script: Redirecting to file gives "Illegal Instruction"

6,633

The $EXECUTE >> $REDIRECT statement is not on line 6 in the script. So the error is not in the script but rather in the executable.

...: line 6: 11927 Illegal instruction: 4 $EXECUTABLE >> $OUTFILE

This is also easy to see because or the error text. "Illegal instruction" means that the CPU can not execute some command. It is theoretically possible, but bash is stable software and these error do not occur in mature software.

The text you replaced with an ellipsis usually contains the executable which died or threw an error. I bet 50 rep it wasn't "bash".

Share:
6,633

Related videos on Youtube

Patrick
Author by

Patrick

A Swiss-made software engineer who likes to play with as many technologies as possible. I'm fluent in Java, dabbled in C#, develop for Android in my spare time. In my job I develop software for businesses, mainly with Eclipse Scout and Java. Also I configure, engineer and maintain our build setup and continuous integration systems, deploy and support our software. #SOreadytohelp

Updated on September 18, 2022

Comments

  • Patrick
    Patrick over 1 year

    I'm trying to use a bash script for a study assignment. As a bash noob, I tried to adapt an existing one to suit my purpose: Compile/Make a C-program with different compile arguments, execute it and redirect its output to a file.

    The script is as follows:

    #!/bin/bash
    EXECUTABLE=./PartitionedHashJoin
    OUTFILE=results.txt
    for sizelog2 in $(seq 0 20)
    do
            for buckets in $(seq 2 2048)
            do
                    size=$((1<<$sizelog2))
                    make clean
                    make PartitionedHashJoin NUM_RELATION_R=$sizelog2 NUM_BUCKETS=$buckets
                    echo -n $sizelog2 " " $buckets " " >> $OUTFILE
                    $EXECUTABLE >> $OUTFILE
            done
    done
    

    However, bash throws an error:

    ...: line 6: 11927 Illegal instruction: 4 $EXECUTABLE >> $OUTFILE

    If I remove the redirecting of the executable's output, then it works.

    I do not get what I could have typed wrong in the redirection - it works just fine in another example with just one loop. Google didn't have a suggestion so far for what I'm doing wrong.

    Can anyone spot it?

    • ott--
      ott-- over 12 years
      What does "file ./PartitionedHashJoin" report? Is that file executable? Try "test -x $EXECUTABLE && $EXECUTABLE >> $OUTFILE".
    • Keith Thompson
      Keith Thompson over 12 years
      It's very unlikely that bash itself threw this error. It's far more likely your PartitionedHashJoin executable is blowing up.
    • Patrick
      Patrick over 12 years
      Aah, you are correct. facepalm The error seems to lie in the executable indeed. Seems to be a weird one though - but at least it's not the bash. Thanks!