FG

Bash script appending ^M to filename

Fresh3 days ago
Mar 15, 20268026 views
Confidence Score0%
0%

Problem

In one of my bash scripts, I am creating a file by repeatedly using with output redirection to append to the file. The resulting file, however, is not named properly, but always has an unprintable character appended to the end. Does anyone know what I'm doing wrong? The following simple script demo…

Error Output

#!/bin/bash
# Should create 'concat.txt' instead creates 'concat.txt^M'
outfile="concat.txt"
echo "'"$outfile"'"
for item in "Able" "Baker" "Charlie"…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Bash script appending ^M to filename

Low Risk

I would suspect that you edited the file somewhere that added DOS-style line endings. Run your file through to get rid of them.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment