From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24461 invoked by alias); 8 Apr 2018 07:39:47 -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: X-Seq: 23318 Received: (qmail 23393 invoked by uid 1010); 8 Apr 2018 07:39:47 -0000 X-Qmail-Scanner-Diagnostics: from mail-lf0-f43.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.215.43):SA:0(-1.9/5.0):. Processed in 1.667805 secs); 08 Apr 2018 07:39:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=QlHGavNPglgVC0N99vYXZX+2nOWnXqX5xWs0V8sTfrI=; b=eD34bxbWgplLO46i3KgwwtuxQdRILvxI6WxzRnbsCY9Svot35d6ejWhM3LtZsmwVkk OV1CD89+t9G6ThkkD/ee6+WGcsFQyF4wCNzCYMCVywqf0CkD2ZGx1uDAOmtO7a5oJrQ5 lfuGO6ndOREd4f7C2tyrse7MRTJwmcyP0++EjATxSt+gWNgvfEX2vz7XLvHul1s7WXRg kE/ELjkz254NSi9Qrf7aDS6OSebipyf+NZ4XJqUZvNhA+xR0ZRefMtVeekRKGObvE/0p d62MoSURDef7rHKTQQOSLA/g1Q328TGqu1kVFONkDh9lFNufoYIacseKgTLCD4G6JcrM BV8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=QlHGavNPglgVC0N99vYXZX+2nOWnXqX5xWs0V8sTfrI=; b=QynFgAyMsr9d3xPwK1cCOaSHkJGoe0XN/z6LuzYnmGvAyKoFu052G0meOKbJsX+X5f TqRG42nDbcAqkRf3ZGeCCBNAoiceqYiJAZ+azR8b91KPJcM+jmMdHio+V3fumhXehdSy F+1vqf7ON1gQ/WP+xJk08zNo4loUe3ew2xi6tHm1rJu3DsaLRCdn8iOCID0qTo0zSbsP BMC4jKRHH+FDwpKEMpIsll2Jd0CV4u3WzSjdAIJVeZY4MIDnlDyQYEaMxHVgy34sniMh sYZRfqCdW61vOQH26Su15rCEeoTgvn4Mdv5BwHg+rQ4QWQ3i52BGFU1LO/0+xWNRw6bs Xy1w== X-Gm-Message-State: ALQs6tADwtsCRjVWQr5hPHCayL+MocGaIpVIDS4S8OyNFg4GDQqtTOhj qb9kVVx6dGNQeNhie/7wVM72GLrri/OQSYORearC6X/P X-Google-Smtp-Source: AIpwx49Sw7II9kH5pDcF7CcW6e4fUkftspUbH2J79iZjKLjh4WOSZ+ptcmOLLDwj5Bi2TvZ3UPuRFCy/CilEdhaato4= X-Received: by 10.46.91.21 with SMTP id p21mr20872419ljb.38.1523173180382; Sun, 08 Apr 2018 00:39:40 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <637434d9-ff23-53d4-5d31-443942fc2ef9@eastlink.ca> References: <604319cb-d86f-686b-ac9b-00d21650edff@eastlink.ca> <637434d9-ff23-53d4-5d31-443942fc2ef9@eastlink.ca> From: Bart Schaefer Date: Sun, 8 Apr 2018 00:39:39 -0700 Message-ID: Subject: Re: activate alias inside subshell To: Zsh Users Content-Type: text/plain; charset="UTF-8" I'm not going to try to respond blow-by-blow to your messages, because there still seem to be some concepts about aliasing that we've discussed in past threads that you don't appear to be applying. Firstly, though, there's something that doesn't add up about your "test1" example; as you quoted it, "yelline" references a variable $yel that's never assigned, and if I attempt to replicate verbatim in a freshly-started shell what you say you've done, I get exactly the errors I expected: % . test1; test1 test1:10: defining function based on alias `msg' test1:14: parse error near `()' zsh: command not found: test1 I suspect you're using a shell in which you've been running other tests and something from an earlier experiment is spilling over to confuse you. Either that, or you haven't actually shown us the full contents of the "test1" file. The fundamental thing you're forgetting is that aliases act by text replacement. "whence" will tell you whether an alias WILL replace text the NEXT time the lexer is invoked, but that has no meaning for text that has previously been parsed. Function definitions are always fully lexed+parsed before they are executed, so once a function is defined any aliases it may have used have been replaced by the expanded text of the alias and can never expand again. We explained this several threads ago when you were shown the "eval" example. "eval" runs the parser again so aliases have a chance to expand. Thus: % alias msg='echo this is an alias' % test1() { msg in test1 } % functions test1 test1 () { echo this is an alias in test1 } % See how the use of the alias is no longer present in the stored definition of test1? Note that it's important that the alias and the function were defined separately (in this example at separate PS1 prompts), so that the parser was run a second time AFTER the alias was defined. Compare running the parser only once, by using a multi-line construct (I have started a fresh "zsh -f" for each of these examples even though I've changed the function names to differentiate them): % { cursh> alias msg='echo this is an alias' cursh> test2() { msg in test2 } cursh> } % functions test2 test2 () { msg in test2 } % test2 test2: command not found: msg % Here test2 was parsed at the same time as the alias command, so the alias was not yet "active" when the body of test2 was read, and thus the alias definition is both not expanded in test2 and also irrelevant at the time the function is executed. However, that has no bearing on what "whence" will say about the current state of the alias at the time the function is executed: % { cursh> alias msg='echo this is an alias' cursh> test3() { whence -v msg; msg } cursh> } % test3 msg is an alias for echo this is an alias test3: command not found: msg % Something like this must be involved in producing the "nulled" output from the example you posted.