Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I have this script:

ROOT=/tmp
LOG=$ROOT/blah.log
echo $LOG

The output is:

/blah.log

obviously the ROOT variable is not being interpolated which is very unexpected. If I echo $ROOT, it correctly shows /tmp. Hence something fishy is going on here.

share

migration rejected from serverfault.com Apr 16 at 10:58

This question came from our site for system and network administrators. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by terdon Apr 16 at 10:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – terdon
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

Let me guess: you edited that script on Windows.

Correct? Your scripts have Windows line endings: CR LF instead of just LF which is the unix line ending character. As far as the shell is concerned, that CR is part of the command, so the value of ROOT contains a CR at the end, and when you print it out, the CR moves the cursor back to the beginning of the line.

The fix is not to edit scripts on Windows, or else to make sure your editor uses unix line endings. Be sure to convert your existing script(s).

See also Directories are listed twice and Carriage return issue

share