Re: test for "command not found" before expanding shell parameters

2014-04-23 Thread Dave Finlay
This might suffice for the initial situation, as long as the expansion is passed in with single quotes: function check_n_run() { greo="$1"; wild="$2" if $(which "$greo" > /dev/null); then $greo $wild; fi } This is too cute to be useful, but it was enjoyable seeing the unintend

Re: test for "command not found" before expanding shell parameters

2014-04-22 Thread Chet Ramey
> On Mon, Apr 21, 2014 at 3:16 AM, Andreas Schwab wrote: > > And if $greo is null the condition will also be true. > > Really? I'll be damned. That explains this problem > I've been having. Yes. `test' operates based on the number of arguments it receives. If you don't quote `$greo' and it e

Re: test for "command not found" before expanding shell parameters

2014-04-22 Thread Alan Young
On Mon, Apr 21, 2014 at 3:16 AM, Andreas Schwab wrote: > And if $greo is null the condition will also be true. Really? I'll be damned. That explains this problem I've been having. -- Alan Young

Re: test for "command not found" before expanding shell parameters

2014-04-21 Thread Andreas Schwab
Alan Young writes: > greo=$(command -v greo) > > if [ -n $greo ]; then > $greo ... > fi > > command will search the directories defined in $PATH for the command > greo and return the fully qualified path. If it isn't found it will > return null. So, if $greo is non-zero, greo exists and you c

Re: test for "command not found" before expanding shell parameters

2014-04-20 Thread Alan Young
greo=$(command -v greo) if [ -n $greo ]; then $greo ... fi command will search the directories defined in $PATH for the command greo and return the fully qualified path. If it isn't found it will return null. So, if $greo is non-zero, greo exists and you can run it. On Sun, Apr 20, 2014 at 1

Re: test for "command not found" before expanding shell parameters

2014-04-20 Thread Alan Young
No, because the $greo semanti /var/db/pkg/*/*/USE line will not be executed at all. The if [ -n $greo ] condition only passes if $greo contains the path of the greo application. On Sun, Apr 20, 2014 at 12:05 PM, Toralf Förster wrote: > On 04/20/2014 07:58 PM, Alan Young wrote: >> greo=$(command

Re: test for "command not found" before expanding shell parameters

2014-04-20 Thread Eduardo A . Bustamante López
On Sun, Apr 20, 2014 at 08:05:08PM +0200, Toralf Förster wrote: > If "greo" does not exist - will bash in that case expand /var/db/pkg/*/*/USE > neverttheless ? I understand that you want this for *interactive* stuff. Storing the command in a variable and then test with 'command -v' surely is too

Re: test for "command not found" before expanding shell parameters

2014-04-20 Thread Toralf Förster
On 04/20/2014 07:58 PM, Alan Young wrote: > greo=$(command -v greo) > > if [ -n $greo ]; then > $greo ... > fi > > command will search the directories defined in $PATH for the command > greo and return the fully qualified path. If it isn't found it will > return null. So, if $greo is non-zero