From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 28710 invoked from network); 29 Jun 2020 16:56:15 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 29 Jun 2020 16:56:15 -0000 Received: (qmail 12088 invoked by alias); 29 Jun 2020 16:56:08 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: Sender: zsh-users@zsh.org X-Seq: 24962 Received: (qmail 27569 invoked by uid 1010); 29 Jun 2020 16:56:08 -0000 X-Qmail-Scanner-Diagnostics: from mail-ot1-f44.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25857. spamassassin: 3.4.4. Clear:RC:0(209.85.210.44):SA:0(-1.9/5.0):. Processed in 2.258134 secs); 29 Jun 2020 16:56:08 -0000 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.210.44 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=/FWqEJRwojReUIvGhpsWRF5h+VyoLDCPDi25YOYfPtI=; b=QD1YfgYxO7As6zHTXcJlf0QaB9zbAiNPVqTZ6IDtTaSLu9E1nifvMKwtzSL8J9dUEp sxiLMvmC3q72apdskriF5BtpPJ7NzYT+zXQXlBTny7g9JH3M7Vol4ECJtYzOgFW7Ma93 lqcogpNvv3bNydSkIP+gkb7jfKfQmMOTiGaOSUiIR8uYA4aiI+CmBtTEqgK4goOSww5u GvyUAA18bhWZpK+iiNTE4FYBoUJiB7GWzVoKgTXuOIQZEzPcRK239u3LewTIyRty5J86 dbD5NHVUv8zHS22UrEGXl2jrg2t4A+q4RipL4Zv64RQwQhuXjABVMgYcxy8sn9meAFIT QDRg== X-Gm-Message-State: AOAM531yBM1nKl3/Hn88+F3azHl8P/G/2j24OTEBpHmSaei9tMQa4NKm //kC64gG9ulb2M8cPuM8nHq82Hfricy2Jr0ewrV5R2AgBSY= X-Google-Smtp-Source: ABdhPJzKPI4rHqLi20DRjs2twzBWdp8KF6KRGu63rKUWPtfpkAWnIg98DZpTKxoWCl/E+xtcWFz1mG3vCzZv4iirLAM= X-Received: by 2002:a05:6830:17ce:: with SMTP id p14mr14844764ota.161.1593449732932; Mon, 29 Jun 2020 09:55:32 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Mon, 29 Jun 2020 09:55:21 -0700 Message-ID: Subject: Re: Alias call in function fails... To: "zsh-users@zsh.org" Cc: Frank Gallacher Content-Type: text/plain; charset="UTF-8" On Mon, Jun 29, 2020 at 9:26 AM Sebastian Gniazdowski wrote: > > I once was testing with Eric on IRC and the aliases sometimes do work > within the same file. I think that the distance between the definition and > usage is important. No, that's unrelated. Code structure and execution context are everything. As Peter explained, initialization files, sourced files, and scripts (that are not function bodies) are executed one newline-separated command at a time (Peter said "line by line" but that's not precisely correct **), whereas function definitions (no matter where they appear, but especially autoloads) are fully parsed before being executed. If you think about it, that latter must be true, otherwise you'd run the function instantly every time you tried to define one. Where you're probably becoming confused is "one newline-separated command at a time". Pipelines, commands joined with ";" or "&&" or "||", and structured commands such as an if/else cascade or a while loop, are all, like a function body, fully parsed before being executed. Even a sequence of commands simply enclosed in braces is fully parsed before being executed. Thus even in an interactive shell: % { alias -g foo=bar cursh> echo foo } foo % echo foo bar % alias -g foo=again ; echo foo bar % echo foo again You have to be certain that the alias command is actually executed, NOT merely seen by the parser, before the first usage of that alias is seen by the parser. Run your confusing script with "setopt xtrace" and watch for the order of execution.