Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!comp.vuw.ac.nz!nickson From: nickson@comp.vuw.ac.nz (Ray Nickson) Newsgroups: gnu.bash.bug Subject: Re: File Name Globbing Message-ID: <8907160207.AA22322@comp.vuw.ac.nz> Date: 16 Jul 89 02:05:56 GMT References: Sender: daemon@tut.cis.ohio-state.edu Distribution: gnu Organization: GNUs Not Usenet Lines: 156 Date: 14 Jul 89 19:15:02 GMT From: bitbug@sun.COM Subject: File Name Globbing It seems what is desired is a variable that toggles globbing between one of two behaviors: The result of a globbing operation that fails causes the shell to return the filename substitution pattern, rather than an error, if the pattern is not matched, i.e. ... *or* a globbing operation that fails causes the shell to print a diagnostic and stop processing the current command or script, i.e. ... All right, time for me to stick my neck out again. The patch at the end implements behaviour that is almost this; I despise csh's `No Match' whingeing so much that I refuse to make an empty glob an error. If this causes some scripts to hang reading stdin, then you bought it, you pay for it. This patch should be considered experimental; I don't intend to put it into the installed bash here. While I like the idea, I'm unhappy that I had to change the globbing semantics to such an extent to make this work comfortably; in particular, I've hacked gloobing so that the first word of a command is _never_ globbed. I can't think why anyone would want the first word globbed, but still... The reason I did this was that `[' is a perfectly valid (and oft-used) command; perhaps the best solution is to say that invalid (as opposed to empty) globbing characters should be left as is. Discussion? Anyway, here's the patch; take it or leave it. It gives current behaviour when nullglobok is unset, and allows empty globs if it's set. -rgn -- nickson@comp.vuw.ac.nz ...!uunet!vuwcomp!nickson + 64 4 721000x8593 PS: I intend to complete one more bash-hack, then revert to writing my thesis for a week or so... :-) --------------------cut here-------------------- *** subst.c.orig Thu Jun 29 15:38:23 1989 --- subst.c Sun Jul 16 13:47:59 1989 *************** *** 1227,1232 **** --- 1227,1235 ---- return (expand_words_1 (list, 0)); } + /* do we accept null globs, or refuse to glob? */ + int nullglobok = 0; + /* The workhorse for expand_words () and expand_words_no_var (). First arg is LIST, a WORD_LIST of words. Second arg DO_VARS is non-zero if you want to do environment and *************** *** 1315,1321 **** WORD_LIST *glob_list; orig_list = (WORD_LIST *)NULL; ! tlist = new_list; if (!disallow_filename_globbing) { --- 1318,1325 ---- WORD_LIST *glob_list; orig_list = (WORD_LIST *)NULL; ! tlist = new_list && nullglobok ? new_list->next : new_list; ! /* nullglobok: chop off word 0 so it doesn't get globbed */ if (!disallow_filename_globbing) { *************** *** 1362,1369 **** if (glob_list) orig_list = (WORD_LIST *)list_append (glob_list, orig_list); ! else ! orig_list = make_word_list (copy_word (tlist->word), orig_list); } else { --- 1366,1374 ---- if (glob_list) orig_list = (WORD_LIST *)list_append (glob_list, orig_list); ! else if (!nullglobok) ! orig_list = ! make_word_list (copy_word (tlist->word), orig_list); } else { *************** *** 1379,1384 **** --- 1384,1394 ---- tlist = tlist->next; } + /* nullglobok: patch word 0 back on */ + if (nullglobok) + orig_list = (WORD_LIST *) + list_append (orig_list, + make_word_list (copy_word (new_list->word), 0)); dispose_words (new_list); new_list = orig_list; } *************** *** 1428,1434 **** /* Not really `extern' just `forward'. */ extern int sv_path (), sv_mail (), sv_terminal (), sv_histsize (), sv_uids (), sv_ignoreeof (), sv_glob_dot_filenames (), sv_histchars (), sv_nolinks (), ! sv_hostname_completion_file (); #ifndef NOJOBS extern int sv_notify (); --- 1438,1444 ---- /* Not really `extern' just `forward'. */ extern int sv_path (), sv_mail (), sv_terminal (), sv_histsize (), sv_uids (), sv_ignoreeof (), sv_glob_dot_filenames (), sv_histchars (), sv_nolinks (), ! sv_hostname_completion_file (), sv_nullglobok (); #ifndef NOJOBS extern int sv_notify (); *************** *** 1456,1461 **** --- 1466,1472 ---- { "histchars", sv_histchars }, { "nolinks", sv_nolinks }, { "hostname_completion_file", sv_hostname_completion_file }, + { "nullglobok", sv_nullglobok }, { (char *)0x00, (Function *)0x00 } }; *************** *** 1475,1480 **** --- 1486,1499 ---- } i++; } + } + + /* what to do just after the nullglobok variable has changed */ + sv_nullglobok () + { + extern int nullglobok; + + nullglobok = (find_variable ("nullglobok") != 0); } /* What to do just after the PATH variable has changed. */