I have a file called test.txt.
the content of the has two line/rows in it
i-08ece3afc
i-0001db77b
so I have done like this but
#!/bin/bash
set -x
head -1 /home/test.txt > /test1.txt #it has now one row in test1.txt
file="/home/test1.txt"
name=$(cat "$file")
echo "name=$name"
but the out is
head -1 /home/test.txt
+ file=/home/test1.txt
++ cat /home/test1.txt
+ name=$'i-08ece3afc\r'
+ echo $'name=i-08ece3afc\r'
name=i-08ece3afc
file1="${name}"
file1= $'i-08ece3afc\r'
and giving ERROR as failed to satisfy constraint: Member must satisfy regular expression pattern: ^[a-zA-Z0-9_:-]{1,400}$ '
I can see the variable name is correct in the output but why name ,echo file1 is giving trailing as $ ' & leading \r'
I am expecting the output as
head -1 /home/test.txt
+ file=/home/test1.txt
++ cat /home/test1.txt
+ name=i-08ece3afc
+ echo name=i-08ece3afc
name=i-08ece3afc
file1="${name}"
file1= i-08ece3afc