Home > database >  Linux setting variables
Linux setting variables

Time:03-08

I'm running a shell script into Linus and I have a unexpected behavior.

bash-4.2$ echo $TOOLBOX_ROOT
/opt/lsas/lsas_datenbank/tools/3rd_Party/ettools

bash-4.2$ export REALSCRIPT="$TOOLBOX_ROOT/sh/dbSchemaSetup.sh"
bash-4.2$ echo $REALSCRIPT
/sh/dbSchemaSetup.shbank/tools/3rd_Party/ettools

It looks like it is not concat both strings but rather it is appending data at the beginning.

Any suggestion?

Regards

CodePudding user response:

When the value of TOOLBOX_ROOT was set, it had a carriage return ($'\r') at the end of it. As a result, the value of the REALSCRIPT variable is now:

/opt/lsas/lsas_datenbank/tools/3rd_Party/ettools\r/sh/dbSchemaSetup.sh

... and when you echo $REALSCRIPT, the \r is interpreted by echo as a carriage return, meaning: move the cursor to the beginning of the line. As a result, the visual output is "/opt/lsas/lsas_datenbank/tools/3rd_Party/ettools" but overwritten at the beginning with "/sh/dbSchemaSetup.sh".

The best option is to prevent the \r from being included in the assignment to TOOLBOX_ROOT.

The second-best option would be to remove it immediately after the assignment, with something like:

TOOLBOX_ROOT=${TOOLBOX_ROOT/%$'\r'/}

... which will remove any carriage return from the end of that variable.

  • Related