Skip to content

compile.sh example script is non-functional on Linux #40

@NickeyMaina

Description

@NickeyMaina

Fix: examples/compile.sh Not a Working Shell Script on Linux

Problem

The examples/compile.sh file contains placeholder syntax that is not valid on Linux:

c4c --input <file_name> --output <file_name> --executable

This causes several issues:

  • Not executable — the file lacks the executable permission bit (chmod +x)
  • No argument handling — it does not accept command-line arguments
  • Syntax errors at runtime — angle-bracket placeholders like <file_name> are interpreted by the shell as input redirection, producing errors such as:
./compile.sh: line 1: <file_name>: No such file or directory

Expected Behaviour

A working example script that:

  1. Accepts a .c4 source file as its first argument
  2. Derives the output executable name from the input filename
  3. Invokes ./bin/c4c with the correct flags
  4. Reports success or failure clearly

Suggested Fix

Replace the contents of examples/compile.sh with the following:

#!/bin/bash
if [ -z "$1" ]; then
    echo "Usage: $0 <file.c4>"
    exit 1
fi

INPUT="$1"
BASENAME=$(basename "$INPUT" .c4)
EXEC_FILE="examples/${BASENAME}_exec"

./bin/c4c -i "$INPUT" -o "$EXEC_FILE" --executable
if [ $? -ne 0 ]; then
echo "Error: C4 compilation failed."
exit 1
fi

echo "Successful"

Then mark the script as executable:

chmod +x examples/compile.sh

What Changed and Why

Issue Fix
Missing shebang Added #!/bin/bash so the OS knows which interpreter to use
No argument handling Added a $1 check with a usage message and clean exit
Hard-coded placeholder paths Used $INPUT and $BASENAME derived from the caller-supplied argument
Wrong flag syntax (--input, --output) Replaced with short flags -i and -o matching the actual c4c CLI
No error propagation Checked $? after compilation and exits with code 1 on failure
Not executable Script should be committed with execute permission (chmod +x)

Usage Example

chmod +x examples/compile.sh
./examples/compile.sh path/to/program.c4

On success, the compiled executable will be written to examples/program_exec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions