Skip to content
Advertisement

Linux setting variables

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

JavaScript

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

Any suggestion?

Regards

Advertisement

Answer

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:

JavaScript

… 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:

JavaScript

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement