2 consecutive 'cut' in a line did not produce expected result

L

leon_ges

Guest
Can anybody see the issue?
I have the following commands:
$ x3=$(grep -i isend x.x | tr -s " " )
$ echo $x3
isEndOfStream = false
$ x3=$(grep -i isend x.x | tr -s " " | cut -d "=" -f 2 )
$ echo $x3
false
$ x3=$(grep -i isend x.x | tr -s " " | cut -d "=" -f 2 | cut -c1-5)
$ echo $x3
fals


Where is 'e'?

But if I further do this:
$ x4=$(echo $x3)
$ echo $x4
false
$ x4=$(echo $x3 | cut -c1-5)
$ echo $x4
false


I got the whole value (false).
Thanks for any explanation and workaround.

Noel
 


It turns out that there is <SPACE> before "false":
$ echo $x3
false
$ echo "$x3"
false

Hence " false" != "false".

Furthermore, there is <CR> at the end of the line hence
$ x4=$(echo $x3)
$ echo $x4
false
$ expr $x4
6
$ x5=$(echo $x3 | cut -c1-5)
$ echo $x5
false
$ expr $x5
5

So now $x5 = "false" can be tested.
 

Members online


Latest posts

Top