bug-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] make function local


From: Linda Walsh
Subject: Re: [Help-bash] make function local
Date: Thu, 16 Apr 2015 22:38:22 -0700
User-agent: Thunderbird



Pierre Gaston wrote:
    >  Is there a particular problem you're trying to solve for which local
    >  functions would be the appropriate solution?
----
Cleanliness.

Not polluting the global namespace.

Ensuring the function can't be called from outside a function.

It's a trite example, but I do something like:


sub gvim () {
 array orig_args=($@)  gv_files=() gv_ops=()
 int use_tab=0  look_for_ops=1

   sub _exec_gvim() {
     array args
     ((use_tab)) && args=("-p")
     (( ${#gv_ops[@]:-0} )) && args+=(${gv_ops[@]})
     (( $# )) && args+=($@)
     command gvim "${args[@]}"
     unset -f _exec_gvim
   }
   ....


AFAIK, _exec_gvim, can only be called from within "function gvim", no?




reply via email to

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