I need to print a received parameter at the end of every line… Here is what I did:
Printing info WITHOUT user:
CODE
user=$1
while read line; do
linearr=($line)
echo "${linearr[2]} ${linearr[0]} ${linearr[3]}"
done
OUTPUT:
b name2 5
c name3 2
a name1 0
Printing info WITH user at the end of each line:
CODE:
user=$1
while read line; do
linearr=($line)
echo "${linearr[2]} ${linearr[0]} ${linearr[3]} $user"
done
OUTPUT:
omare2 5
omare3 2
omare1 0
If I print the user (echo $user) it prints normally the name (omar)…
Why is this happening?
Most likely
${linearr[3]}ends with a\r. ($usercould also start with that char.)(This could happen if you’re redirecting from a file with Windows-type line endings
\r\n.)