Solved

Scripts in Cygwin acting strangely

Posted on 2007-03-20
4
317 Views
Last Modified: 2013-11-15
Bash scripting in my Cygwin environment that used to work so well is now acting strangely.

To illustrate see how variable $i works with echo but fails with ls, given a file like this...
$ cat /tmp/psif
pointsec
pointsec/docs
pointsec/docs/Architecture.doc

And a script like this...
$ cat /tmp/ww
#!/usr/bin/bash -x
for i in `cat /tmp/psif`
do
echo $i
ls -dl $i
read x
done

When I run it with -x for debgging I get this....
$ /tmp/ww
++ cat /tmp/psif
+ for i in '`cat /tmp/psif`'
+ echo $'pointsec\r'
pointsec
+ ls -dl $'pointsec\r'
: No such file or directory
+ read x

+ for i in '`cat /tmp/psif`'
+ echo $'pointsec/docs\r'
pointsec/docs
+ ls -dl $'pointsec/docs\r'
: No such file or directorydocs
+ read x

+ for i in '`cat /tmp/psif`'
+ echo $'pointsec/docs/Architecture.doc\r'
pointsec/docs/Architecture.doc
+ ls -dl $'pointsec/docs/Architecture.doc\r'
: No such file or directorydocs/Architecture.doc
+ read x

Anyone have an idea what's going on?
0
Comment
Question by:veedar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 18758150

Yes, the directory you are trying to 'ls' does not exist in the path from wich you are executing the script.

"No such file or directory docs/Architecture.doc"

0
 
LVL 15

Author Comment

by:veedar
ID: 18758315
I wish it was that easy...they do exist...

$ ls -ld pointsec pointsec/docs pointsec/docs/Architecture.doc
drwxr-xr-x+ 4 veedar Domain Users      0 Mar 19 13:30 pointsec
drwxr-xr-x+ 2 veedar Domain Users      0 Mar 16 10:48 pointsec/docs
-rwxr-xr-x  1 veedar Domain Users 128512 Mar 13 10:37 pointsec/docs/Architecture.doc
0
 
LVL 58

Accepted Solution

by:
amit_g earned 500 total points
ID: 18758478
/tmp/psif is created using a DOS editor and has \r in the end. Do

dos2unix /tmp/psif

and then use your same script.
0
 
LVL 15

Author Comment

by:veedar
ID: 18758667
Thanks amit_g dos2unix fixed it.  I thought I had already checked for a DOS issue but I guess not.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question