Solved

Scripts in Cygwin acting strangely

Posted on 2007-03-20
4
311 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Let’s list some of the technologies that enable smooth teleworking. 
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now