From: "Dan Luther" <dan@theluthers.net>
To: "'Benjamin R. Haskell'" <zsh@benizi.com>
Cc: <zsh-users@zsh.org>
Subject: RE: Using variables in command substitution
Date: Mon, 14 Jun 2010 11:57:45 -0500 [thread overview]
Message-ID: <003001cb0be2$b82332a0$286997e0$@net> (raw)
In-Reply-To: <alpine.LNX.2.01.1006140924520.5029@hp.internal>
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
prev parent reply other threads:[~2010-06-14 17:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-14 6:18 Dan Luther
2010-06-14 9:02 ` Peter Stephenson
2010-06-14 14:58 ` Dan Luther
2010-06-14 13:36 ` Benjamin R. Haskell
2010-06-14 16:57 ` Dan Luther [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='003001cb0be2$b82332a0$286997e0$@net' \
--to=dan@theluthers.net \
--cc=zsh-users@zsh.org \
--cc=zsh@benizi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).