Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: simplify and if then else
- X-seq: zsh-users 13287
- From: "Mikael Magnusson" <mikachu@xxxxxxxxx>
- To: zzapper <david@xxxxxxxxxx>
- Subject: Re: simplify and if then else
- Date: Wed, 24 Sep 2008 14:03:56 +0200
- Cc: zsh-users@xxxxxxxxxx, "Peter Stephenson" <pws@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:cc:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=/hmewK9+YHszxeqar9TodgMGTvPhaqh3+3xLXPr0kkQ=; b=RAvj6HfMb1FtQ5G+f9N2A3yRaC+91QTmvNlg4if1CobuUahefhoetTZCRTjMayEW5s CM7zZR9/Li/pMmj8/PvOvzptiXmUmudC7YRrt4mA941mLZ2sYEUtGwUUZf0JhtMX9muP 7NGdCa0WaV7xXh1uJP9w8vyCBdb45iMw7Ppz4=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=d9NfVAG75J1zmrm3lY/dRQG0cPNgWHHL5A3Hz/Uy2DfPrsaPu6xlsQb1Z+FSngO858 jntHYOzVpbfF3r/I6Nkc4/9FSJjDXSbnRdlyfiuIBaHzj54mu4/A1KR7qVoL5r2u8wK3 TBmiYV83XeUItdiUjYlSPSs0ZnKbZVzJNQ1hA=
- In-reply-to: <237967ef0809240453o7187b09cy5ed7cdd726c5dd13@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <Xns9B237D944CFB3zzappergmailcom@xxxxxxxxxxxx> <200809241144.m8OBiQhd017368@xxxxxxxxxxxxxx> <237967ef0809240453o7187b09cy5ed7cdd726c5dd13@xxxxxxxxxxxxxx>
2008/9/24 Mikael Magnusson <mikachu@xxxxxxxxx>:
> 2008/9/24 Peter Stephenson <pws@xxxxxxx>:
>> zzapper wrote:
>>> Hi
>>> Having a Homer Simpson moment, but this must be easy to simplify
>>> if [[ "$LOGNAME" != davidr ]]
>>> then
>>> cd /o/inetpub/wwwdev/www.some.co.uk/epsystem/epadmin
>>> else
>>> cd /c/inetpub/wwwdev/www.some.co.uk/epsystem/epadmin
>>> fi
>>>
>> cd \
>> ${${${LOGNAME:#davidr}:+/o}:-/c}/inetpub/wwwdev/www.some.co.uk/epsystem/epadmin
>>
>> although if LOGNAME is empty it's treated the same as if it were davidr;
>> if that's an issue it gets even more clumsy:
>>
>> ${${${${LOGNAME:-x}:#davidr}:+/o}:-/c}
>
> A bit longer but arguably still simpler :)
> cd /$([[ "$LOGNAME" != davidr ]] && echo o || echo c)/inetpub/wwdev/blabla
If all you want to do is avoid writing the full dirname twice, this also
works in very new versions:
() {
local dir
if [[ "$LOGNAME" != davidr ]]; then
dir=o
else
dir=c
fi
cd /$dir/inetpub/wwwdev/www.some.co.uk/epsystem/epadmin
}
If it's not a very new version, you have to name the function. Or hope the
variable name is unique.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author