jeudi 23 juin 2016

Concatenating 2 BASH variables is throwing up weird value

I've got some variables that are being passed through various machines (via php and other bash scripts) and eventually ending up on the last server.

I'm using these variables to populate a mysql database entry.

It all works fine until I try to concatenate 2 of the variables together for one of the entries which results in a completely wrong variable being entered in to the database.

This is an example of the variables as they arrive at the script :

$4=48
$6=101216

And the script runs fine if I use them individually :

mysql --host=localhost --user=xxxx --password=xxxx db_name <<EOF
insert into db_table (uid, ts_id) values ('$4', '$6');
EOF

As expected the uid field gets populated with 48, and ts_id gets populated with 101216

But if I try to concatenate them for a third field...

userID="$4";
trackID="$userID$6";

mysql --host=localhost --user=xxxx --password=xxxx db_name <<EOF
insert into db_table (uid, ts_id, track_id) values ('$4', '$6', '$trackID');
EOF

... instead of 48101216 being entered into the track_id field I'm getting 8388607

Is there some weird math going on or is this an error code being generated?

I've also tried concatenating them like this :

trackID=$4$6;

Like this :

trackID="$4$6"

And like this :

insert into db_table (uid, ts_id, track_id) values ('$4', '$6', '$4$6');

But they all result in the mystical 8388607 ??

Even if the numbers in both variables are different each time I run it, I always end up with 8388607 when I concatenate them?

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire