Post #36,561
4/26/02 2:38:57 AM
|
Mad bash behaviour
Here's something you can try in the comfort of your own home:
Using /bin/bash as your shell, do this:
peter:~ $ cd test peter:~/test $ pwd /home/peter/test peter:~/test $ ls peter:~/test $ touch *.php peter:~/test $ ls *.php peter:~/test $ ls -l total 0 -rw-r--r-- 1 peter peter 0 Apr 26 07:25 *.php peter:~/test $ rm \\*.php
Yep, when there are no files in the directory, bash passes the * to touch without expanding it, thus making a file called "*.php".
Question for the peanut gallery. Do you consider this behaviour broken? I do, and so, apparently does csh:
peter:~/test $ csh % ls % touch *.php touch: No match.
Peter [link|http://www.debian.org|Shill For Hire] [link|http://www.kuro5hin.org|There is no K5 Cabal]
|
Post #36,564
4/26/02 4:02:25 AM
|
Re: Mad bash behaviour
ksh does it too:
pklowesd@peter:PK-USA > mkdir test pklowesd@peter:PK-USA > cd test pklowesd@peter:PK-USA > touch *.sdl pklowesd@peter:PK-USA > ls *.sdl pklowesd@peter:PK-USA > rm *.sdl pklowesd@peter:PK-USA >
Even does it in a non-empty directory:
pklowesd@peter:PK-USA > cd testsql pklowesd@peter:PK-USA > ls item-search.sql onight.sql ord.sql pklowesd@peter:PK-USA > touch *.sdl pklowesd@peter:PK-USA > ls *.sdl item-search.sql onight.sql ord.sql pklowesd@peter:PK-USA > ls -l total 6 -rw-rw-rw- 1 pklowesd dw_pk 0 Apr 26 01:50 *.sdl -rw-rw-rw- 1 pklowesd dw_pk 140 Apr 10 10:14 item-search.sql -rw-rw-rw- 1 pklowesd dw_pk 114 Jan 11 14:03 onight.sql -rw-rw-rw- 1 pklowesd dw_pk 114 Feb 28 16:36 ord.sql pklowesd@peter:PK-USA > rm *sdl pklowesd@peter:PK-USA > ls item-search.sql onight.sql ord.sql pklowesd@peter:PK-USA >
tcsh, predictably, gives: > cd test > ls > touch *.sdl touch: No match. >
bash on my system gives same results you saw, although I didn't try it in a non-empty directory. man pages on any of the systems used were not helpful.
Interesting.
----- Steve
|
Post #36,574
4/26/02 8:00:49 AM
|
Hmmm.... some do.. some don't
I tried it on cygwin on my Win2k box with expected results. Then I tried it on a solaris box and it broke. Very strange...
Hugh
$ pwd /home/hnichole
hnichole@HNICHOLE-2000 ~ $ mkdir junkwaffle
hnichole@HNICHOLE-2000 ~ $ cd junkwaffle
hnichole@HNICHOLE-2000 ~/junkwaffle $ touch *.tst touch: creating `*.tst': No such file or directory
hnichole@HNICHOLE-2000 ~/junkwaffle $ bash --version GNU bash, version 2.05a.0(3)-release (i686-pc-cygwin) Copyright 2001 Free Software Foundation, Inc.
hnichole@HNICHOLE-2000 ~/junkwaffle $
bash-2.05$ pwd /users/hnichole bash-2.05$ mkdir junkwaffle bash-2.05$ cd junkwaffle bash-2.05$ touch *.tst bash-2.05$ ls -al total 48 -rw-rw-r-- 1 hnichole eng 0 Apr 26 04:52 *.tst drwxrwxr-x 2 hnichole eng 4096 Apr 26 04:52 . drwxrwxrwx 18 hnichole eng 20480 Apr 26 04:52 .. bash-2.05$ bash --version GNU bash, version 2.05.0(2)-release (sparc-sun-solaris2.5.1) Copyright 2000 Free Software Foundation, Inc.
|
Post #36,633
4/26/02 8:22:02 PM
|
Planned insane POSIX bash behaviour
Well it appears as though it must be UNIX... as Windoze doesn't support those kinds of special characters as allowed names PERIOD.(Which means never will be POSIX compliant) Hope this explains a bunch. Been in there a long while if it is broken. I believe it ain't, as those chars are required by Posix... which was built "kinda" around "ksh".
gfolkert@KNIGHT ~ $ uname -a CYGWIN_NT-5.0 KNIGHT 1.3.10(0.51/3/2) 2002-02-25 11:14 i686 unknown gfolkert@KNIGHT ~ $ mkdir foo gfolkert@KNIGHT ~ $ cd foo gfolkert@KNIGHT ~/foo $ touch *.foo touch: creating `*.foo': No such file or directory gfolkert@KNIGHT ~/foo $ bash --version GNU bash, version 2.05a.0(3)-release (i686-pc-cygwin) Copyright 2001 Free Software Foundation, Inc. gfolkert@KNIGHT ~/foo $ ssh squire gfolkert@SQUIRE's password: gfolkert@SQUIRE ~ $ uname -a CYGWIN_NT-5.0 SQUIRE 1.3.10(0.51/3/2) 2002-02-25 11:14 i686 unknown gfolkert@SQUIRE ~ $ mkdir foo gfolkert@SQUIRE ~ $ cd foo gfolkert@SQUIRE ~/foo $ touch *.foo touch: creating `*.foo': No such file or directory gfolkert@SQUIRE ~/foo $ bash --version GNU bash, version 2.05a.0(3)-release (i686-pc-cygwin) Copyright 2001 Free Software Foundation, Inc. gfolkert@SQUIRE ~/foo $ exit logout Connection to squire closed. gfolkert@KNIGHT ~/foo $ ssh stimpy gfolkert@stimpy's password: Last login: Thu Apr 25 14:30:17 EDT 2002 from :20
Welcome to: stimpy
Please remember that activities are monitored, which may include session reconstruction.
[gfolkert@stimpy gfolkert]$ uname -a Linux stimpy 2.4.16 #1 Fri Dec 7 09:07:26 EST 2001 i686 unknown [gfolkert@stimpy gfolkert]$ mkdir foo [gfolkert@stimpy gfolkert]$ cd foo [gfolkert@stimpy ~/foo]$ touch *.foo [gfolkert@stimpy ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert users 0 Apr 26 18:56 *.foo [gfolkert@stimpy ~/foo]$ bash --version GNU bash, version 2.05.8(1)-release (i386-redhat-linux-gnu) Copyright 2000 Free Software Foundation, Inc. [gfolkert@stimpy ~/foo]$ ssh raider gfolkert@raider's password: Last successful login for gfolkert: Thu Apr 18 16:48:41 EDT 2002 from :1
Welcome to: raider
Please remember that activities are monitored, which may include session reconstruction.
[gfolkert@raider gfolkert]$ uname -a OSF1 raider V5.0 1094 alpha [gfolkert@raider gfolkert]$ mkdir foo [gfolkert@raider gfolkert]$ cd foo/ [gfolkert@raider ~/foo]$ touch *.foo [gfolkert@raider ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert staff 0 Apr 26 18:57 *.foo [gfolkert@raider ~/foo]$ bash --version GNU bash, version 2.04.0(1)-release (alpha-dec-osf5.0) Copyright 1999 Free Software Foundation, Inc. [gfolkert@raider ~/foo]$ rm \\*.foo [gfolkert@raider ~/foo]$ ksh [gfolkert@raider ~]$ cd foo [gfolkert@raider ~/foo]$ touch *.foo [gfolkert@raider ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert staff 0 Apr 26 18:57 *.foo [gfolkert@raider ~/foo]$ exit [gfolkert@raider ~/foo]$ exit logout Connection to raider closed. [gfolkert@stimpy ~/foo]$ ssh serv gfolkert@serv's password: Last login: Thu Apr 18 16:50:27 EDT 2002 from :7
Welcome to: serv
Please remember that activities are monitored, which may include session reconstruction.
[gfolkert@serv gfolkert]$ uname -a OSF1 serv V4.0 878 alpha [gfolkert@serv gfolkert]$ mkdir foo [gfolkert@serv gfolkert]$ cd foo [gfolkert@serv ~/foo]$ touch *.foo [gfolkert@serv ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert staff 0 Apr 26 18:58 *.foo [gfolkert@serv ~/foo]$ bash -version GNU bash, version 1.14.7(1) [gfolkert@serv ~/foo]$ rm \\*.foo [gfolkert@serv ~/foo]$ ksh [gfolkert@serv ~]$ cd foo [gfolkert@serv ~/foo]$ touch *.foo [gfolkert@serv ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert staff 0 Apr 26 18:58 *.foo [gfolkert@serv ~/foo]$ exit [gfolkert@serv ~/foo]$ exit logout Connection to serv closed. [gfolkert@stimpy gfolkert]$ ssh namer gfolkert@namer's password: Last login: Fri Apr 19 07:51:52 2002 from stimpy
Valid and Authorized connections only: namer
Please remember that activities are monitored, which may include session reconstruction.
[gfolkert@namer /gfolkert]# bash -version GNU bash, version 1.14.7(1) [gfolkert@namer gfolkert]$ uname -a Linux namer 2.0.36 #1 Tue Oct 13 22:17:11 EDT 1998 i586 unknown [gfolkert@namer gfolkert]$ mkdir foo [gfolkert@namer gfolkert]$ cd foo [gfolkert@namer ~/foo]$ touch *.foo [gfolkert@namer ~/foo]$ ls -l total 0 -rw-r--r-- 1 gfolkert users 0 Apr 26 19:00 *.foo [gfolkert@namer ~/foo]$ exit logout Connection to namer closed. [gfolkert@stimpy gfolkert]$ [gfolkert@stimpy ~/foo]$ exit Connection to stimpy closed. gfolkert@KNIGHT ~/foo $ exit
There you see....
Now if you look you may see some interesting things about the environ I run... ;) As only the names have been trucated or changed to protect the innocent (or me Really)
greg, curley95@attbi.com -- REMEMBER ED CURRY!!!
|
Post #36,661
4/27/02 10:56:33 AM
|
Not sure about that
I agree that Windows does not have a mechanism for special characters, which is why Cygwin works correctly. In unix you can use wild card characters in names if you escape them. Consistant behavior requires that unescaped wild cards be expanded and passed to the calling program as arguements. *.whatever in an empty directory expands to null. Either touch is inconsistant with the rest of the usual unix utilities (read broke) or the shell(s) are broke in this instance. If you forgive broken behaviour because it's been around a long time, then I guess Windows is really OK then, hmmm?
/ducks, snickering, and runs
Hugh
|
Post #36,663
4/27/02 11:52:08 AM
|
Pathname Expansion
I think the big difference here is that the Unix shells are responsible for pathname expansion. For instance (in bash on Linux): sh-2.04$ ls -l DER*pdf -rw-r--r-- 1 morganek users 9720 Oct 16 2001 DEReport.pdf sh-2.04$ set -o noglob sh-2.04$ cp DER*pdf mtestme.pdf cp: DER*pdf: No such file or directory sh-2.04$ set +o noglob sh-2.04$ cp DER*pdf mtestme.pdf sh-2.04$ ls -l mtestme.pdf -rw-r--r-- 1 morganek users 9720 Apr 27 11:47 mtestme.pdf sh-2.04$
What is significant here is that the command, "cp", does not do pathname expansion. The expansion is handled by bash and passed to cp. On the Windows side, the COMMAND.COM/CMD.EXE shells do not do expansion when parsing input to determine what to load. As an example, the XCOPY.EXE (or .COM--I forget) executable is responsible for expanding wildcards.
-Mike
|
Post #36,662
4/27/02 11:36:11 AM
|
Not Broken
This is not broken behavior. The globbing definition in bash is (from the man page):
"If no matching file names are found, and the shell option nullglob is disabled, the word is left unchanged. If the nullglob option is set, and no matches are found, the word is removed."
I can think of one advantage of this behavior: This permits the passing of wildcards when using scp to copy from a remote host.
-Mike
|
Post #36,664
4/27/02 1:04:32 PM
|
Thanks
That'll teach me to RTFM.
I'm glad you can turn off this behaviour, as it would be a royal pain in the patooty if you couldn't.
Peter [link|http://www.debian.org|Shill For Hire] [link|http://www.kuro5hin.org|There is no K5 Cabal]
|
Post #36,760
4/29/02 10:03:40 AM
|
No it won't
That'll teach me to RTFM.
If you don't already know that, then this one more example won't teach you. But then, since you deal with (l)users all the time, you already know that, too, don't you?
=== I can't be a Democrat because I like to spend the money I make. I can't be a Republican because I like to spend the money I make on drugs and whores.
|
Post #36,777
4/29/02 12:00:11 PM
|
you can also touch *
I remember a system with a broken backup that had the * as a filename in the data directory. If you run accross this use rm "*" to take it out. thanx, bill
TAM ARIS QUAM ARMIPOTENS
|
Post #36,786
4/29/02 12:28:21 PM
|
I can imagine the conversation:
Sysadmin: Is this your file?
User: That's not my asterisk.
Sysadmin: Damn right! That's *my* ass you hung on the line.
-Mike
|