bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: feature request: file_not_found_handle()


From: Ken Irving
Subject: Re: feature request: file_not_found_handle()
Date: Wed, 21 Aug 2013 02:22:24 -0800
User-agent: Mutt/1.5.20 (2009-06-14)

On Tue, Aug 20, 2013 at 04:44:57PM +0200, Roman Rakus wrote:
> You are badly using features of bash. Write a script which will do
> things for you, or use any other language/shell.

There's only one feature being used, a hook that bash calls in 
the event that a command is not found.  The request is just to
extend that behavior to other cases of the command not being found.
In either case, bash is done with the command anyway, giving up
on it, about to emit an error message and quit.  So what's the 
harm is using the hook to do something else?

> Please, accept this response as a suggestion.
> 
> command_not_found_handle is designed to do other things than you are
> expecting.

The only use I've seen, and I think where it originated, was a way
to suggest packages for installation when a command failed but could
be provided by a package.  Kind of a gimmick, perhaps, but sometimes
probably useful and a neat trick, maybe also potentially annoying.

I don't know about Andreas' application, but mine is largely written
in bash, and is a way to deploy systems using mostly shell scripting or
whatever other programs or languages you might want to use.

Your suggestion was:

> .... Write a script which will do
> things for you, or use any other language/shell.

I did write such a script, and can use it directly and have done
so a lot.  But the convenience of calling it automatically is  
significant, and makes for a very natural extension to the 
shell, in my opinion of course.

The 'bad' commands that bash is failing are not likely to be
confused with other commands, as few commands have . in the 
name.  But even if they did, bash would just run them anyway.

Here's a method, the only one in a simple type that is for grouping some
objects together and dispatching another method on them in random order.

    $ cat $(ambler.method dispatch)
    #!/bin/bash
    method=$1 && shift
    test -n "$method" || exit
    for s in $(ls|shuf); do
        tob $s.$method "$@" &
    done

Just a bash script, no tricks.  On the command line, with the
command-not-found hook, I'd omit the tob and let it be called
implicitly, for convenience.

I think this use is orthogonal to bash, and not in conflict 
with it.

Ken

> 
> 
> RR
> 
> On 08/19/2013 10:29 PM, Andreas Gregor Frank wrote:
> >Hi Chet,
> >
> >sorry, i thought you talk about the bash code.
> >I didn't want to show my own usecase but now i have to ;-):
> >I have a File class and can construct a File "object" for example:
> >File anObjectName /etc/passwd
> >and then i can do
> >e.g. anObjectName.getInode (this already works with
> >command_not_found_handle() )
> >But if i do a:
> >File /etc/passwd /etc/passwd
> >and then
> >/etc/passwd.getInode (i think it would be nice if the normal files in a
> >filesystem could be treated like objects)
> >then there is nothing that triggers the command_not_found_handle() to split
> >"object" and method...
> >So at the moment slashes are forbidden in object names in my fun project.
> >
> >Now you know why your bash example for ckexec() isn't a solution for me.
> >
> >bye
> >Andreas
> >
> >
> >2013/8/19 Chet Ramey <chet.ramey@case.edu>
> >
> >>On 8/19/13 6:57 AM, Andreas Gregor Frank wrote:
> >>>Hi Chet,
> >>>
> >>>I have no idea if there is "enough" demand, but i think there will be
> >>some
> >>>ideas to use this feature...
> >>>I still think it is a question of consistency to be able to handle a "No
> >>>such file or directory event", if i can do this with a "command not found
> >>>event" (independent of the command_not_found_handle history).
> >>>
> >>>You say you can easily test whether or not if the file in the pathname
> >>exists.
> >>
> >>That is not what I said.  I said that you, the script writer, can check
> >>whether or not a filename containing a slash is executable before
> >>attempting to execute it.  Maybe a function something like this (untested):
> >>
> >>ckexec()
> >>{
> >>         case "$1" in
> >>         */*)    ;;
> >>         *)      "$@"  ; return $? ;;
> >>         esac
> >>
> >>         if [ -x "$1" ]; then
> >>                 "$@"
> >>         else
> >>                 other-prog "$@"
> >>         fi
> >>}
> >>
> >>
> >>Chet
> >>--
> >>``The lyf so short, the craft so long to lerne.'' - Chaucer
> >>                  ``Ars longa, vita brevis'' - Hippocrates
> >>Chet Ramey, ITS, CWRU    chet@case.edu
> >>http://cnswww.cns.cwru.edu/~chet/
> >>
> 
> 

-- 
Ken.Irving@alaska.edu, 907-474-6152
Water and Environmental Research Center
Institute of Northern Engineering
University of Alaska, Fairbanks



reply via email to

[Prev in Thread] Current Thread [Next in Thread]