[SOLVED] bash: echo $variable without carriage return
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hmm.. Then are you sure you don't have something in your ~/.bashrc or similar startup script?
Try creating a fresh user (or, hell, try while beeing root -- just be sure it's a login shell, so do "su - root", or "sudo bash --login") and see if the JAVA_HOME variable still has problems.. The point is to pin-point if it's a system-wide script problem or just some script that gets executed when you login..
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by Smokey_justme
@jlinkels: Echo will add an <LF> character by default at the end (without the -n option) .. It has nothing to do with the problem at hand and it doesn't really matter in rknichols code (which was focused on the inner echo fixing the <CR> in the variable).. Moreover, -n option will not suppress any <LF>'s added by you, it will only not add a new one..
I think I had a serious off-day. Too bad some replies quoted me, so it doesn't even make sense to delete my posts.
vi (and its clones) will detect that the file has DOS-style CR-LF line endings and will work in that mode, saving the file in that same format. If you look at the status line at the bottom of the screen when the file is first read, you will see "[dos]". To save such a file with Unix-style line endings, you would need to change the fileformat before saving it:
Code:
:set ff=unix
Or, you could just run the dos2unix command on the file to change its line endings.
I used @rknichols trick to set vim with the right properties and then saved the file.
@Smokey_justme thanks for your suggestion and the little coding. That got me a little step further in understanding things.
Thanks!
Robbert
ps I still don't understand how that file got the carriage. I'm very sure I did not have that on a Windows computer. I think the file in the java package must have already contained the error.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.