From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6224 invoked by alias); 14 Jun 2010 17:28:49 -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: X-Seq: 15122 Received: (qmail 20426 invoked from network); 14 Jun 2010 17:28:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at eigbox.net designates 66.96.184.10 as permitted sender) X-EN-OrigOutIP: 10.20.18.16 X-EN-IMPSID: Vsxv1e0070LoEWa01sxv5K From: "Dan Luther" To: "'Benjamin R. Haskell'" Cc: References: <001201cb0b89$63e2e3b0$2ba8ab10$@net> In-Reply-To: Subject: RE: Using variables in command substitution Date: Mon, 14 Jun 2010 11:57:45 -0500 Message-ID: <003001cb0be2$b82332a0$286997e0$@net> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: AcsL2Fsiej0BYhgzQiqhM2kEeKS4IQAClQGQ Content-Language: en-us X-EN-UserInfo: 2dff425fffc153c1d61e4aff1ab5a5c9:a0a1756f2a50e17c16dccfa3fe4abe21 X-EN-AuthUser: dan@theluthers.net Sender: "Dan Luther" X-EN-OrigIP: 70.234.103.251 X-EN-OrigHost: adsl-70-234-103-251.dsl.tul2ok.sbcglobal.net Thank you -- that's VERY good information! -----Original Message----- From: Benjamin R. Haskell [mailto:zsh@benizi.com] Sent: Monday, June 14, 2010 8:37 AM To: Dan Luther Cc: zsh-users@zsh.org Subject: Re: Using variables in command substitution On Mon, 14 Jun 2010, Dan Luther wrote: > Hello, > > I'm hoping someone can explain this. > > I'm trying to unify my .zshrc across a couple of platforms, and I ran across > an interesting ZSH behavior. Essentially, I want to assign a variable to the > name of a specific command for later substitution: > > if [$(uname)="SunOS"]; then > ME="/usr/xpg4/bin/id -un" > elif [$(uname)="Linux"]; then > ME="id -un" > else > ME="who am i | cut -d ' ' -f1" > fi > HNAME=$(uname -n | cut -d. -f1) > . . . > cd() { chdir "$@"; prompt="[$($ME)@$HNAME] $(pwd)> "; } > . . . > > When I try to use the "cd" redefinition, I get: > > .zshrc: no such file or directory /usr/xpg4/bin/id -un > > Is it possible to use variables in command expansion at all, or am I > just doing it wrong? > Disregarding the problem as stated, a much simpler version of getting your prompt the way it seems you want it: setopt prompt_subst prompt='[%n@%m] %~> ' Vastly simpler than trying to find the information yourself across multiple systems. Plus two improvements IMO: 1. shortened hostname (Use '%M' instead of '%m' if you want the full thing) 2. shortened pathnames ('%~' will try to compress the directory using named directories; use '%/' or '%d' [equivalent] if you want the full thing) Look for 'SIMPLE PROMPT ESCAPES' in man zshall (probably in some subsection, but I never know which is which -- wasn't 'zshparam' or 'zshexpn'). -- Best, Ben No virus found in this incoming message. Checked by AVG - www.avg.com Version: 9.0.829 / Virus Database: 271.1.1/2934 - Release Date: 06/14/10 01:35:00