Context
- OS: Ubuntu 18.04.6 LTS
- Text editor: GNU nano, 2.9.3
In the BASH script below, I'm trying to create directories using mkdir. The name of each directory is determined by a combination of variable values, which are determined by reading in rows of a specified CSV (see here). All of this is happening in a Linux environment.
Current script
#!/bin/bash
# Read in 4 variable values line by line
while IFS=, read -r m M n gtalpha; do
# Create a directory based on variable values
mkdir ./output/QUAC_m${m}_M${M}_n${n}_ga${gtalpha}
# Dummy follow-up command here, which uses this output folder
done < subset_denovo.params
Here's the subset_denovo.params file being referenced:
3,8,8,0.01
4,4,4,0.05
5,4,4,0.05
6,2,2,0.05
7,1,1,0.01
Expected output
Folders (within the directory output/) with the names:
QUAC_m3_M8_n8_ga0.01
QUAC_m4_M4_n4_ga0.05
QUAC_m5_M4_n4_ga0.05
QUAC_m6_M2_n2_ga0.05
QUAC_m7_M1_n1_ga0.01
Problem: Actual Output
Instead, the folder names are:
'QUAC_m3_M8_n8_ga0.01'$'\r'
'QUAC_m4_M4_n4_ga0.05'$'\r'
'QUAC_m5_M4_n4_ga0.05'$'\r'
'QUAC_m6_M2_n2_ga0.05'$'\r'
'QUAC_m7_M1_n1_ga0.01'$'\r'
I understand that the '$'\r' is the Linux carriage return, but I don't understand why it's being appended to the folder name, or how to prevent it. Encasing the mkdir argument in quotes (see below) doesn't address the issue:
mkdir "./output/QUAC_m${m}_M${M}_n${n}_ga${gtalpha}" # <-- same result
I've seen this post describing a similar problem with the scp command, but am unable to recreate the solution in this (simpler) context. This post says the cause of the issue is probably an API library, but I don't know what library could cause the problem in this context.
Is this a BASH problem? A nano problem? Any input on preventing this behavior would be appreciated.