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:
- Accepts a
.c4 source file as its first argument
- Derives the output executable name from the input filename
- Invokes
./bin/c4c with the correct flags
- 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.
Fix:
examples/compile.shNot a Working Shell Script on LinuxProblem
The
examples/compile.shfile contains placeholder syntax that is not valid on Linux:This causes several issues:
chmod +x)<file_name>are interpreted by the shell as input redirection, producing errors such as:Expected Behaviour
A working example script that:
.c4source file as its first argument./bin/c4cwith the correct flagsSuggested Fix
Replace the contents of
examples/compile.shwith the following:Then mark the script as executable:
What Changed and Why
Usage Example
On success, the compiled executable will be written to
examples/program_exec.