From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23275 invoked by alias); 15 Jun 2010 02:13:53 -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: 15123 Received: (qmail 14500 invoked from network); 15 Jun 2010 02:13:42 -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 benizi.com designates 64.130.10.15 as permitted sender) Date: Mon, 14 Jun 2010 09:36:43 -0400 (EDT) From: "Benjamin R. Haskell" To: Dan Luther cc: zsh-users@zsh.org Subject: Re: Using variables in command substitution In-Reply-To: <001201cb0b89$63e2e3b0$2ba8ab10$@net> Message-ID: References: <001201cb0b89$63e2e3b0$2ba8ab10$@net> User-Agent: Alpine 2.01 (LNX 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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