Good afternoon community, I'm having a problem with bash scripting and I hope you can help me! First of all, to understand what the objective is, the script must open a file, read each line inside, and then according to the line open a folder with the name of that line and edit a file inside. Here's an example:
Bash script:
#!/bin/bash
input="/test/sensor/test"
while IFS= read -r line; do
echo "worked" >> /test/sensor/$line/test.txt
done < "$input"
inside /test/sensor/test
test1
test2
test3
So at this point the script should open and edit:
/test/sensor/test1/test.txt
/test/sensor/test2/test.txt
/test/sensor/test3/test.txt
However it doesn't work and I get the error:
/test.txt: No such file or directory/test1
/test.txt: No such file or directory/test2
/test.txt: No such file or directory/test3
First of all I would like to say that this exact script already worked in 2019, and now it seems that it is not working.
Some extra information:
- The file has 777 permissions
- All files/folders listed exist
- If I replace for example /test/sensor/$line/test.txt with /test/sensor/test1/test.txt it will work, but I need it with $line