Make the Welcome Toolkit Run Correctly

LinuxBeginner
Practice Now

Introduction

OPEN CIRCLE is preparing an afternoon of community arts. Its welcome toolkit displays the complete programme, including Chloé Martín, 林雨,佐藤葵 and João Silva. A correct sample works; the newly exported copy does not.

You will repair a separate delivery while preserving the original files. Basic terminal familiarity is enough. You will learn why permission, a script's first line and text encoding are different questions. The supplied reader is ready to use; you do not write Python or a general-purpose converter.

Use the browser Terminal throughout. The sample data and terminal output retain their original language in every translated lesson.

Repair the Launcher without Changing the Originals

In this step, you will compare a working toolkit with an export and create a directly executable delivery launcher. Use Terminal.

Read the real result first

cd changes your working directory. ./ means execute a file relative to this directory; a slash tells the shell to use that path rather than search command names. Start with the supplied sample:

cd /home/labex/project/event
./sample/start.sh
OPEN CIRCLE | Afternoon

14:00 — Welcome / Chloé Martín
14:30 — 纸艺工坊 / 林雨
15:15 — 音の庭 / 佐藤葵
16:00 — Café & questions / João Silva

Read every line, including the blank separator. These are the actual bytes decoded by the supplied reader, not a screenshot or a success label. cat prints text. Read the export receipt before choosing a conversion:

cat source/export-receipt.txt

The receipt declares UTF-8 with CRLF for start.sh and UTF-16-LE with a BOM for programme.txt. The other files are already UTF-8 with LF. A file extension cannot establish an encoding.

Separate permission from the interpreter entry

ls -l shows permissions; an x indicates execution permission. The first line of a script, its shebang, starts with #! and names an interpreter. Direct execution needs both a usable interpreter entry and permission. Try the exported launcher; this failure is intentional:

ls -l source/start.sh
./source/start.sh

Expect permission denied. Changing text cannot grant permission. bash file instead asks Bash to read the file, bypassing direct execution and its shebang. This particular script places a comment after its command, so its trailing CR is in that comment. Try it:

bash source/start.sh

Expect Cannot read programme.txt and a UTF-8 decode error. That is a different failure: the reader was reached, but could not decode the data. Explicit Bash invocation is useful evidence here; it is not proof that direct execution is ready.

cp -a copies a directory's contents and preserves file modes. The /. means its contents, including any hidden files. Create a delivery copy; leave source/ and sample/ unchanged. mkdir -p creates the directory and any missing parents; it also succeeds when the directory already exists. chmod u+x adds execute permission for the file owner (u), without changing the other permissions:

mkdir -p delivery
cp -a source/. delivery/
chmod u+x delivery/start.sh
./delivery/start.sh

Now direct execution still fails, with an interpreter error such as bad interpreter: /bin/bash^M: no such file or directory. Some shells report cannot execute: required file not found. The script exists; the CR byte at the end of the interpreter path is the problem. Do not keep retrying chmod.

Inspect bytes and fix only the script line endings

LF is byte 0a; CRLF is 0d 0a. file offers a format description based on byte patterns. od -An -tx1 -N16 prints the first 16 bytes as hexadecimal, omitting address labels. Use the receipt and bytes together; file is not an infallible encoding detector:

file source/start.sh source/programme.txt
od -An -tx1 -N16 source/start.sh

The shebang ends with 0d 0a. Line endings and character encoding are separate properties: the script is already UTF-8. Linux applications can read CRLF text; this failure concerns the interpreter path in a directly executed script.

sed 's/\r$//' replaces a CR only at a line's end with nothing. The single quotes preserve the expression; $ means end of line. > writes standard output to a different file, replacing it on retry. Never redirect onto the input: the shell would erase it before sed reads it. && runs the next command only when the previous command succeeded. mv then renames the completed temporary file:

sed 's/\r$//' source/start.sh > delivery/start.tmp && mv delivery/start.tmp delivery/start.sh
chmod u+x delivery/start.sh
od -An -tx1 -N16 delivery/start.sh
./delivery/start.sh

The shebang now ends in 0a. The last command reaches Cannot read programme.txt, just as the explicit Bash call did. This is progress to the data boundary, not completion of the whole toolkit. If you made a mistake, repeat the conversion from source/start.sh and restore execute permission; do not edit the original.

Convert the Programme and Use the Independent Delivery

In this step, you will decode the declared UTF-16 source, retain all programme text and use the delivery from another directory. Continue in Terminal at /home/labex/project/event.

Use the source encoding evidence

A character encoding maps characters to bytes. UTF-8 and UTF-16 can represent these same names using different bytes. A BOM (byte order mark) at a UTF-16 file's start records byte order: ff fe means little endian; fe ff means big endian. Both are UTF-16. A BOM is useful evidence here, not a universally harmful prefix.

od -An -tx1 -N16 source/programme.txt

The opening ff fe agrees with the receipt's UTF-16-LE declaration. The reader's documented contract requires UTF-8 without a BOM. It accepts CRLF in text data, but cannot decode these UTF-16 bytes as UTF-8. Stripping CR bytes or renaming the extension cannot perform that decoding.

iconv -f UTF-16 -t UTF-8 decodes a BOM-bearing UTF-16 input and encodes it as UTF-8. -f gives the source format, -t the target; UTF-16 uses the BOM to select the byte order. Save to a temporary destination and promote it only on success:

iconv -f UTF-16 -t UTF-8 source/programme.txt > delivery/programme.tmp && mv delivery/programme.tmp delivery/programme.txt
file delivery/programme.txt
od -An -tx1 -N16 delivery/programme.txt
cat delivery/programme.txt

The first bytes are the title's UTF-8 bytes, not ff fe, fe ff or the UTF-8 BOM ef bb bf. Read every name against the sample: removing non-ASCII characters would lose the event's content even if the resulting file decoded.

If iconv reports an error, its output may be partial. The && prevents promotion of that partial file. Check the declared source encoding and rerun from the unchanged source; do not use -c or //IGNORE to silently discard characters. This lesson covers intact, declared encodings, not guessing or repairing corrupted exports.

Preserve the files that already work

about.sh and door-sign.txt were already correct; they need no conversion. cmp compares bytes, printing nothing and returning success for identical files. The two comparisons below should be silent:

cmp source/about.sh delivery/about.sh
cmp source/door-sign.txt delivery/door-sign.txt
./delivery/about.sh
cat delivery/door-sign.txt

Expect the community arts description and Bienvenue · 欢迎 · ようこそ. Conversion is a response to evidence and an input contract, not a mandatory treatment for every file.

Hand over and actually run the toolkit

The launcher finds reader.py relative to its own location; the reader similarly finds programme.txt. Change to an unrelated directory and use the absolute launcher path. A usable handover must not depend on the author's current directory or an explicit bash workaround:

cd /tmp
/home/labex/project/event/delivery/start.sh

Expect exactly the complete four-entry afternoon programme shown earlier, in its original order and with the blank separator. You have used the actual delivered files. Compare Chloé Martín, 林雨,佐藤葵 and João Silva; a zero exit status alone would not prove their text survived.

Return to the project:

cd /home/labex/project/event

To retry, regenerate the affected file from source/. Do not feed an already converted UTF-8 output back into iconv -f UTF-16: that declares the wrong source encoding. Preserve the working files and repeat the final direct launch after any change. Other applications may accept other encodings or BOMs; these requirements belong to this toolkit's documented contract.

Summary

You separated direct execution permission, shebang line endings and data encoding. You delivered and ran a complete UTF-8 programme, preserving all names, order and already-correct files. The independent evening challenge uses the same methods with different source evidence.