LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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....
Code:
#!/bin/bash
# This line works as expected....
echo "the user is <$USER> and the hostname is <$HOSTNAME>"
MYVAR1=bill
MYVAR2=fred
# This lines doesn't.....
echo "my first variable is<$MYVAR1> and my second is <$MYVAR2>"
The output I get is this...
Quote:
$ 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, 11:24 AM   #2
veerain
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

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

Original Poster
Rep: Reputation: Disabled
Quote:
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, 07:03 AM   #4
Fulliautomatix
LQ Newbie
 
Registered: Jan 2015
Posts: 3

Original Poster
Rep: Reputation: Disabled
Fixed!

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!

Thanks
 
  


Reply



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 10:22 AM
Echo Command Dougj75 Linux - Newbie 2 02-28-2012 07:09 PM
echo command vinothaa Linux - Newbie 5 06-05-2010 08:15 AM
Command echo Corrado Linux - Newbie 3 11-11-2009 06: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 03:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:45 PM.

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