[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function in an executable file that can be sourced or executed
From: |
Seth David Schoen |
Subject: |
Re: function in an executable file that can be sourced or executed |
Date: |
Sun, 5 May 2024 19:09:34 -0700 |
Mike McClain writes:
> I have an executable file ~/bin/net that does the hocus pocus to bring
> eth0 up and down. In another file, ~/bin/user.bash is a function, net(),
> that does the same thing yet can be sourced.
> Is there a way that I can put function net() in executable file ~/bin/net
> with a call at the end like: [ if not sourced ] && net;
> In other words, if ~/bin/net is called from the command line the
> function will be executed?
There might be a more official way, but you can certainly check the
contents of $0 or of $(basename $0).