removal of return carriage baffling me?

hi ALL,

bash-3.00$ echo $BASH_VERSION
3.00.16(1)-release

I'm stumped on a bug. Im extracting a checksum value at the end of a file and storing it in a variable, the problem is that it is also somehow storing the carriage return in the string as show below:

The variables below both contain the value of 11

line_count=11
line_count_f=11

in the script when I issue echo "abc"$line_count"def"
I get

abc11def

this is fine...howvere when I issue the command echo "efg"$line_count_f"hij"

I get

hij11

any ideas how to get rid of the return carriage

Thanks in advance

Satnam

You should put the variable in {} brackets....

i.e. echo "efg"${line_count}_f"hij"

The reason is the the _ is a valid character to have in a variable name, and the whole string "line_count_f"hij" is taken as the variable name.

(and you don't need the inner quotes. They serve no purpose here.

Hi

thanks for the reply but it dosnt solve my problem..

there are 2 variable line_count and line_count_f

both contain the value 11 but line_count_f contains it with a return carriage.

I need a way of stripping the return carriage?

Regards
Satnam

Can you show the command you use to get the checksum into the variable?

HI mate,

thanks for persisteing, but i managed to resolve the issue using the tr command to remove the carriage return ie

line_count_f=`echo ${line_count_f} | tr -d '\r'`

No errors now :slight_smile:

Kind regards
Satnam