Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 01-10-2015, 10:53 AM   #1
LQ Newbie
Registered: Jan 2015
Posts: 3

Rep: Reputation: Disabled
misbehaving 'echo' command on Cygwin


I've used unix before, but have just started to play with CYGWIN (1.1.3) on windows XP (32 bit). I'm having trouble getting 'echo' to behave as I would expect.

I've created a script called runstuff which contains these lines....
# This line works as expected....
echo "the user is <$USER> and the hostname is <$HOSTNAME>"
# This lines doesn't.....
echo "my first variable is<$MYVAR1> and my second is <$MYVAR2>"
The output I get is this...
$ runstuff
the user is <Mike> and the hostname is <MikesLaptop>
> and my second is <fredl
In the first echo statement it is just echoing a couple of external variables - this works as expected. In the 2nd echo example the two variables are internal, but the displayed output isn't what I'd expect, my guess is that the first part of the output "my first variable is <bill" has somehow been overwritten by the remainder of the string. Or am I missing something?

I have tried exporting the variables, and I've experimented with wrapping them in quotes, but the results are always the same.

Any help gratefully received.
Old 01-10-2015, 12:24 PM   #2
Senior Member
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
Try enclosing variables in parentheses "{}". Like

echo "${MYVAR1} and ${MYVAR2}"
Old 01-10-2015, 03:36 PM   #3
LQ Newbie
Registered: Jan 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Try enclosing variables in parentheses "{}". Like
Thanks, but I tried that - makes no difference at all.

I'm pretty sure that what I'm doing is good on most normal Unix installations, my guess is this is a limitation or 'feature' of cygwin
Old 01-12-2015, 08:03 AM   #4
LQ Newbie
Registered: Jan 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled

Ok, finally got it now. The text editor I was using (EditPlus) was set to 'dos' mode, so each line was terminated with a "\n" and "\r". As soon as I changed it to 'unix' mode, the line terminator was changed to "\n" only.

The file then started behaving itself!



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
cygwin simple tar command fails when issues on command line deannad Linux - General 1 06-12-2013 11:22 AM
Echo Command Dougj75 Linux - Newbie 2 02-28-2012 08:09 PM
echo command vinothaa Linux - Newbie 5 06-05-2010 09:15 AM
Command echo Corrado Linux - Newbie 3 11-11-2009 07:44 PM
Have you ever used cygwin, i've met a problem with the command stat from cygwin andy820303 Linux - Newbie 0 03-11-2009 04:37 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:02 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration