OSDN Git Service

Fix error in "Why doesn't my script work?", add note about 'mount -x'.
[pf3gnuchains/pf3gnuchains3x.git] / winsup / doc / how-using.texinfo
1 @section Using Cygwin
2
3 @subsection How should I set my PATH?
4
5 If you look at the "Cygwin 1.1.0" (or similar) shortcut created in the
6 "Cygnus Solutions" programs folder, you'll see that it runs
7 @code{C:\cygwin\bin\cygwin.bat} (assuming your root is
8 @code{C:\cygwin}).  The contents should look something like this:
9
10 @example
11         @@echo off
12         SET MAKE_MODE=unix
13         SET PATH=C:\cygwin\bin;C:\cygwin\usr\local\bin;%PATH%
14         bash
15 @end example
16
17 Effectively, this @strong{prepends} /usr/bin and /usr/local/bin to your
18 Windows system path.  If you choose to reset your PATH, say in
19 $HOME/.bashrc, then you should follow this rule.  You @strong{must} have
20 @code{/usr/bin} in your PATH @strong{before} any Windows system
21 directories.  (And you must not omit the Windows system directories!)
22 Otherwise you will likely encounter all sorts of problems
23 running Cygwin applications.
24
25 If you haven't messed up the default mounts, then @code{/bin} and
26 @code{/usr/bin} are the same location, so you only need one of them in
27 your PATH.  You should use @code{/usr/local/bin} for installing
28 additional Cygwin applications that are not part of the core net
29 release.  (That is, anything not found in an ftp mirror of @code{latest}
30 and installed by @code{setup.exe}.)
31
32 @subsection How do I convert between Windows and UNIX paths?
33
34 Use the 'cygpath' utility.  Type '@code{cygpath}' with no arguments to
35 get usage information.  For example (on my installation):
36 @example
37         bash$ cygpath --windows ~/.bashrc
38         D:\starksb\.bashrc
39         bash$ cygpath --unix C:/cygwin/bin/cygwin.bat
40         /usr/bin/cygwin.bat
41         bash$ cygpath --unix C:\\cygwin\\bin\\cygwin.bat
42         /usr/bin/cygwin.bat
43 @end example
44 Note that bash interprets the backslash '\' as an escape character, so
45 you must type it twice in the bash shell if you want it to be recognised
46 as such.
47
48 @subsection Why doesn't bash read my .bashrc file on startup?
49
50 Your .bashrc is read from your home directory specified by the HOME
51 environment variable.  It uses /.bashrc if HOME is not set.  So you need
52 to set HOME correctly, or move your .bashrc to the top of the drive
53 mounted as / in Cygwin.
54
55 @subsection How can I get bash filename completion to be case insensitive?
56
57 "shopt -s nocaseglob" should do the trick.
58
59 @subsection Can I use paths/filenames containing spaces in them?
60
61 Cygwin does support spaces in filenames and paths.  That said, some
62 utilities that use the library may not, since files don't typically
63 contain spaces in Unix.  If you stumble into problems with this, you
64 will need to either fix the utilities or stop using spaces in filenames
65 used by Cygwin tools.
66
67 In particular, bash interprets space as a word separator.  You would have
68 to quote a filename containing spaces, or escape the space character.
69 For example:
70 @example
71         bash-2.03$ cd '/cygdrive/c/Program Files'
72 @end example
73 or
74 @example
75         bash-2.03$ cd /cygdrive/c/Program\ Files
76 @end example
77
78 @subsection Why can't I cd into a shortcut to a directory?
79
80 Cygwin does not follow MS Windows Explorer Shortcuts (*.lnk files).  It
81 sees a shortcut as a regular file and this you cannot "cd" into it.
82
83 Some people have suggested replacing the current symbolic link scheme
84 with shortcuts.  The major problem with this is that .LNK files would
85 then be used to symlink Cygwin paths that may or may not be valid
86 under native Win32 non-Cygwin applications such as Explorer.
87
88 @subsection I'm having basic problems with find.  Why?
89
90 Make sure you are using the find that came with Cygwin and that you
91 aren't picking up the Win32 find command instead.  You can verify that
92 you are getting the right one by doing a "type find" in bash.
93
94 @subsection Why doesn't man work?
95
96 Even after installing the @samp{man} package, you get an error like this:
97
98 @example
99         bash-2.03$ man man
100         Error executing formatting or display command.
101         System command (cd /usr/man ; (echo -e ".pl 1100i"; cat /usr/man/man1/man.1; echo ".pl \n(nlu+10") | /usr/bin/tbl | /usr/bin/groff -Tascii -mandoc | less -is) exited with status 32512.
102         No manual entry for man
103 @end example
104
105 You also need /bin/sh, which is found in the @samp{ash} package.
106 Install this too.
107
108 @subsection Why doesn't chmod work?
109
110 @samp{ntsec} will allow UNIX permissions in Windows NT on NTFS file systems.
111
112 @samp{ntea} works on NTFS @emph{and} FAT but it creates a huge,
113 @strong{undeletable} file on FAT filesystems.
114
115 There is no solution at all for Windows 9x.
116
117 These are settings for the @samp{CYGWIN} environment variable.  See the
118 Cygwin User's Guide at
119 @file{http://sources.redhat.com/cygwin/cygwin-ug-net/cygwin-ug-net.html}
120 for more information on this variable and its settings.
121
122 @subsection Why doesn't @samp{mkdir -p} work on a network share?
123
124 Unfortunately, you cannot do something like this:
125
126 @example
127 bash$ mkdir -p //MACHINE/Share/path/to/new/dir
128 mkdir: cannot create directory `//MACHINE': No such file or directory
129 @end example
130
131 This is because mkdir checks for the existence of each directory on the
132 path, creating them as necessary.  Since @samp{//MACHINE} is not a
133 directory (you can't cd to it either), mkdir tries to create it, and
134 fails.
135
136 This might get fixed someday, but for now, you have to work around it:
137
138 @example
139 bash$ cd //MACHINE/Share
140 bash$ mkdir -p path/to/new/dir
141 @end example
142
143 @subsection Why doesn't my script work?
144
145 There are two basic problems you might run into.  One is the fact that
146 /bin/sh is really ash, and is missing some features you might expect in
147 /bin/sh.  For example:
148
149 @itemize bullet
150 @item No job control
151 @item No getopts
152 @item No functions exported
153 @end itemize
154
155 Or it could be a permission problem, and Cygwin doesn't understand that
156 your script is executable.  Because @samp{chmod} may not work (see FAQ
157 entry above), Cygwin must read the contents of files to determine if
158 they are executable.  If your script does not start with
159
160 @example
161         #! /bin/sh
162 @end example
163
164 (or any path to a script interpreter, it does not have to be /bin/sh)
165 then Cygwin will not know it is an executable script.  The Bourne shell
166 idiom
167
168 @example
169         :
170         # This is the 2nd line, assume processing by /bin/sh
171 @end example
172
173 also works.
174
175 Note that you can use @samp{mount -x} to force Cygwin to treat all files
176 under the mount point as executable.  This can be used for individual
177 files as well as directories.  Then Cygwin will not bother to read files
178 to determine whether they are executable.
179
180 @subsection Why don't cursor keys work under Win95/Win98?
181
182 @strong{(Please note: This section has not yet been updated for the latest
183 net release.)}
184
185 Careful examination shows that they not just non-functional, but
186 rather behave strangely, for example, with NumLock off, keys on numeric
187 keyboard work, until you press usual cursor keys, when even numeric
188 stop working, but they start working again after hitting alphanumeric
189 key, etc. This reported to happen on localized versions of Win98 and
190 Win95, and not specific to Cygwin (there're known cases of Alt+Enter
191 (fullscreen/windowed toggle) not working and shifts sticking with
192 other programs). The cause of this problem is Microsoft keyboard
193 localizer which by default installed in 'autoexec.bat'. Corresponding
194 line looks like:
195
196 @example
197 keyb ru,,C:\WINDOWS\COMMAND\keybrd3.sys
198 @end example
199
200 (That's for russian locale.) You should comment that line if you want
201 your keys working properly. Of course, this will deprive you of your
202 local alphabet keyboard support, so you should think about
203 another localizer. exUSSR users are of course knowledgable of Keyrus
204 localizer, and it might work for other locales too, since it has keyboard
205 layout editor. But it has russian messages and documentation ;-(
206 Reference URL is http://www.hnet.ru/software/contrib/Utils/KeyRus/
207 (note the you may need to turn off Windows logo for Keyrus to operate
208 properly).
209
210 @subsection Is it OK to have multiple copies of the DLL?
211
212 You should only have one copy of the Cygwin DLL on your system.  If you
213 have multiple versions, they will conflict and cause problems.
214
215 If you get the error "shared region is corrupted" it means you have
216 multiple versions of cygwin1.dll running at the same time.  This could
217 happen, for example, if you update cygwin1.dll without exiting @emph{all}
218 Cygwin apps (including inetd) beforehand.
219
220 @subsection Where can I find "more"?
221
222 If you are looking for the "more" pager, you should use the "less" pager
223 instead.
224
225 @subsection Where can I find "which"?
226
227 There is no "which" command with Cygwin.  However, you can use the bash
228 shell builtin "type" which does something similar.
229
230 @subsection How can I access other drives?
231
232 You have some flexibility here.
233
234 Cygwin has a builtin "cygdrive prefix" for drives that are not mounted.
235 You can access any drive, say Z:, as '/cygdrive/z/'.
236
237 In some applications (notably bash), you can use the familiar windows
238 <drive>:/path/, using posix forward-slashes ('/') instead of Windows
239 backward-slashes ('\').  (But see the warning below!)  This maps in the
240 obvious way to the Windows path, but will be converted internally to use
241 the Cygwin path, following mounts (default or explicit).  For example:
242 @example
243         bash$ cd C:/Windows
244         bash$ pwd
245         /cygdrive/c/Windows
246 @end example
247 and
248 @example
249         bash$ cd C:/cygwin
250         bash$ pwd
251         /
252 @end example
253 for a default setup.  You could also use backward-slashes in the
254 Windows path, but these would have to be escaped from the shell.
255
256 @strong{Warning:} There is some ambiguity in going from a Windows path
257 to the posix path, because different posix paths, through different
258 mount points, could map to the same Windows directory.  This matters
259 because different mount points may be binmode or textmode, so the
260 behaviour of Cygwin apps will vary depending on the posix path used to
261 get there.
262
263 You can avoid the ambiguity of Windows paths, and avoid typing
264 "/cygdrive", by explicitly mounting drives to posix paths.  For example:
265 @example
266         bash$ mkdir /c
267         bash$ mount c:/ /c
268         bash$ ls /c
269 @end example
270 Then @samp{/cygdrive/c/Windows} becomes @samp{/c/Windows} which is a
271 little less typing.
272
273 Note that you only need to mount drives once.  The mapping is kept
274 in the registry so mounts stay valid pretty much indefinitely.
275 You can only get rid of them with umount, or the registry editor.
276
277 The '-b' option to mount mounts the mountpoint in binary mode
278 ("binmode") where text and binary files are treated equivalently.  This
279 should only be necessary for badly ported Unix programs where binary
280 flags are missing from open calls.  It is also the setting for /,
281 /usr/bin and /usr/lib in a default Cygwin installation.  The default for
282 new mounts is text mode ("textmode"), which is also the mode for all
283 "cygdrive" mounts.
284
285 You can change the default @samp{cygdrive} prefix and whether it is
286 binmode or textmode using the @code{mount} command.  For example,
287 @example
288         bash$ mount -b --change-cygdrive-prefix cygdrive
289 @end example
290 will change all @code{/cygdrive/...} mounts to binmode.
291
292 @subsection How can I copy and paste into Cygwin console windows?
293
294 Under Windows NT, open the properties dialog of the console window.
295 The options contain a toggle button, named "Quick edit mode".  It must
296 be ON.  Save the properties.
297
298 Under Windows 9x, open the properties dialog of the console window.
299 Select the Misc tab.  Uncheck Fast Pasting.  Check QuickEdit.
300
301 @subsection What does "mount failed: Device or resource busy" mean?
302
303 @strong{(Please note: This section has not yet been updated for the latest
304 net release.)}
305
306 This usually means that you are trying to mount to a location
307 already in use by mount.  For example, if c: is mounted as '/'
308 and you try to mount d: there as well, you will get this error
309 message.  First "umount" the old location, then "mount" the new one and
310 you should have better luck.
311
312 If you are trying to umount '/' and are getting this message, you may
313 need to run @code{regedit.exe} and change the "native" key for the '/'
314 mount in one of the mount points kept under
315 HKEY_CURRENT_USER/Software/Cygnus Solutions/CYGWIN.DLL setup/<version>
316 where <version> is the latest registry version associated with the
317 Cygwin library.
318
319 @subsection How can I share files between Unix and Windows?
320
321 During development, we have both Unix boxes running Samba and
322 NT/Windows 95/98 machines.  We often build with cross-compilers
323 under Unix and copy binaries and source to the Windows system
324 or just toy with them directly off the Samba-mounted partition.
325 On dual-boot NT/Windows 9x machines, we usually use the FAT
326 filesystem so we can also access the files under Windows 9x.
327
328 @subsection Are mixed-case filenames possible with Cygwin?
329
330 Several Unix programs expect to be able to use to filenames
331 spelled the same way, but with different case.  A prime example
332 of this is perl's configuration script, which wants @code{Makefile} and
333 @code{makefile}.  WIN32 can't tell the difference between files with
334 just different case, so the configuration fails.
335
336 In releases prior to beta 16, mount had a special mixed case option
337 which renamed files in such a way as to allow mixed case filenames.  We
338 chose to remove the support when we rewrote the path handling code for
339 beta 16.  The standard Windows apps -- explorer.exe,
340 cmd.exe/command.com, etc. -- do not distinguish filenames that differed
341 only in case, resulting in some (very) undesirable behavior.
342
343 Sergey Okhapkin had maintained a mixed-case patch ('coolview') until
344 about B20.1, but this has not been updated to recent versions of Cygwin.
345
346 @subsection What about DOS special filenames?
347
348 Files cannot be named com1, lpt1, or aux (to name a few); either as
349 the root filename or as the extension part.  If you do, you'll have
350 trouble.  Unix programs don't avoid these names which can make things
351 interesting.  E.g., the perl distribution has a file called
352 @code{aux.sh}.  The perl configuration tries to make sure that
353 @code{aux.sh} is there, but an operation on a file with the magic
354 letters 'aux' in it will hang.
355
356 @subsection When it hangs, how do I get it back?
357
358 If something goes wrong and the tools hang on you for some reason (easy
359 to do if you try and read a file called aux.sh), first try hitting ^C to
360 return to bash or the cmd prompt.
361
362 If you start up another shell, and applications don't run, it's a good
363 bet that the hung process is still running somewhere.  Use the Task
364 Manager, pview, or a similar utility to kill the process.
365
366 And, if all else fails, there's always the reset button/power switch.
367 This should never be necessary under Windows NT.
368
369 @subsection Why the weird directory structure?
370
371 Why do /lib and /usr/lib (and /bin, /usr/bin) point to the same thing?
372
373 Why use mounts instead of symbolic links?
374
375 Can I use a disk root (e.g., C:\) as Cygwin root?  Why is this discouraged?
376
377 After a new installation in the default location, your mount points will
378 look something like this:
379
380 @example
381 Device              Directory           Type         Flags
382 C:\cygwin\bin       /usr/bin            user         binmode
383 C:\cygwin\lib       /usr/lib            user         binmode
384 C:\cygwin           /                   user         binmode
385 @end example
386
387 Note that /bin and /usr/bin point to the same location, as do /lib and
388 /usr/lib.  This is intentional, and you should not undo these mounts
389 unless you @emph{really} know what you are doing.
390
391 Various applications and packages may expect to be installed in /lib or
392 /usr/lib (similarly /bin or /usr/bin).  Rather than distinguish between
393 them and try to keep track of them (possibly requiring the occasional
394 duplication or symbolic link), it was decided to maintain only one
395 actual directory, with equivalent ways to access it.
396
397 Symbolic links had been considered for this purpose, but were dismissed
398 because they do not always work on Samba drives.  Also, mounts are
399 faster to process because no disk access is required to resolve them.
400
401 Note that non-cygwin applications will not observe Cygwin mounts (or
402 symlinks for that matter).  For example, if you use WinZip to unpack the
403 tar distribution of a Cygwin package, it may not get installed to the
404 correct Cygwin path.  @emph{So don't do this!}
405
406 It is strongly recommended not to make the Cygwin root directory the
407 same as your drive's root directory, unless you know what you are doing
408 and are prepared to deal with the consequences.  It is generally easier
409 to maintain the Cygwin hierarchy if it is isolated from, say, C:\.  For
410 one thing, you avoid possible collisions with other (non-cygwin)
411 applications that may create (for example) \bin and \lib directories.
412 (Maybe you have nothing like that installed now, but who knows about
413 things you might add in the future?)
414
415 @subsection How do anti-virus programs like Cygwin?
416
417 Users have reported that NAI (formerly McAfee) VirusScan for NT (and
418 others?) is incompatible with Cygwin.  This is because it tries to scan
419 the newly loaded shared memory in cygwin1.dll, which can cause fork() to
420 fail, wreaking havoc on many of the tools.  (It is not confirmed that
421 this is still a problem, however.)
422
423 There have been several reports of NAI VirusScan causing the system to
424 hang when unpacking tar.gz archives.  This is surely a bug in VirusScan,
425 and should be reported to NAI.  The only workaround is to disable
426 VirusScan when accessing these files.  This can be an issue during
427 setup, and is discussed in that FAQ entry.
428
429 Some users report a significant performance hit using Cygwin when their
430 anti-virus software is enabled.  Rather than disable the anti-virus
431 software completely, it may be possible to specify directories whose
432 contents are exempt from scanning.  In a default installation, this
433 would be @samp{@code{C:\cygwin\bin}}.  Obviously, this could be
434 exploited by a hostile non-Cygwin program, so do this at your own risk.
435
436 @subsection Why can't I run bash as a shell under NT Emacs?
437
438 The Windows port of GNU Emacs (aka "NT emacs") uses the Windows command
439 shell by default.  Also, since Emacs is not a Cygwin application, it has
440 no knowledge of Cygwin mounts.  With those points in mind, you need to
441 add the following code to your ~/.emacs or ~/_emacs file in order to use
442 bash.  This is particularly useful for the JDE package
443 (@file{http://sunsite.dk/jde/}).
444
445 @example
446         ;; This assumes that Cygwin is installed in C:\cygwin (the
447         ;; default) and that C:\cygwin\bin is not already in your
448         ;; Windows Path (it generally should not be).
449         ;;
450         (setq exec-path (cons "C:/cygwin/bin" exec-path))
451         (setenv "PATH" (concat "C:\\cygwin\\bin;" (getenv "PATH")))
452         ;;
453         ;; NT-emacs assumes a Windows command shell, which you change
454         ;; here.
455         ;;
456         (setq process-coding-system-alist '(("bash" . undecided-unix)))
457         (setq w32-quote-process-args ?\")
458         (setq shell-file-name "bash")
459         (setenv "SHELL" shell-file-name) 
460         (setq explicit-shell-file-name shell-file-name) 
461         ;;
462         ;; This removes unsightly ^M characters that would otherwise
463         ;; appear in the output of java applications.
464         ;;
465         (add-hook 'comint-output-filter-functions
466                   'comint-strip-ctrl-m)
467 @end example
468
469 @subsection info error "dir: No such file or directory"
470
471 Cygwin packages install their info documentation in the /usr/info
472 directory.  But you need to create a @code{dir} file there before the
473 standalone info program (probably @code{/usr/bin/info}) can be used to
474 read those info files.  This is how you do it:
475 @example
476         bash$ cd /usr/info
477         bash$ for f in *.info ; do install-info $f dir ; done
478 @end example
479 This may generate warnings:
480 @example
481         install-info: warning: no info dir entry in `gzip.info'
482         install-info: warning: no info dir entry in `time.info'
483 @end example
484 The @code{install-info} command cannot parse these files, so you will
485 have to add their entries to @code{/usr/info/dir} by hand.
486
487 @subsection Why do I get a message saying Out of Queue slots?
488
489 @strong{(Please note: This section has not yet been updated for the latest
490 net release.)}
491
492 "Out of queue slots!" generally occurs when you're trying to remove
493 many files that you do not have permission to remove (either because
494 you don't have permission, they are opened exclusively, etc).  What
495 happens is Cygwin queues up these files with the supposition that it
496 will be possible to delete these files in the future.  Assuming that
497 the permission of an affected file does change later on, the file will
498 be deleted as requested.  However, if too many requests come in to
499 delete inaccessible files, the queue overflows and you get the message
500 you're asking about.  Usually you can remedy this with a quick chmod,
501 close of a file, or other such thing.  (Thanks to Larry Hall for
502 this explanation).
503
504 @subsection Why don't symlinks work on samba-mounted filesystems?
505
506 Symlinks are marked with "system" file attribute.  Samba does not
507 enable this attribute by default.  To enable it, consult your Samba
508 documentation and then add these lines to your samba configuration
509 file:
510
511 @smallexample
512         map system = yes
513         create mask = 0775
514 @end smallexample
515
516 Note that the 0775 can be anything as long as the 0010 bit is set.
517
518 @subsection Why does df report sizes incorrectly.
519
520 @strong{(Please note: This section has not yet been updated for the latest
521 net release.)}
522
523 There is a bug in the Win32 API function GetFreeDiskSpace that
524 makes it return incorrect values for disks larger than 2 GB in size.
525 Perhaps that may be your problem?
526
527 @subsection Has the screen program been ported yet?
528
529 @strong{(Please note: This section has not yet been updated for the latest
530 net release.)}
531
532 Screen requires either unix domain sockets or fifoes.  Neither of
533 them have been implemented in Cygwin yet.
534