Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: zsh bash compatibility question
- X-seq: zsh-users 13012
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: William Scott <wgscott@xxxxxxxxxxxxxxxxxx>
- Subject: Re: zsh bash compatibility question
- Date: Wed, 9 Jul 2008 22:04:29 -0700
- Cc: zsh-users@xxxxxxxxxx
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=d200803; d=spodhuis.org; h=Received:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=gw0lLLI4NA4GRPpn9UwJbyJjtn1C3dbaUfStq9oZM3td0XSspiiBl+DAX2rJo2dJUAq+iQiZDqi1cRZbPlZGY06hx1PNWxJPD7T1QAZMmu3nUeqSDol1vvp3JnQn+45L3Dc31XirOFoEFrP+RA5PSRVgXAZKwpK5k2GYa70pf4c=;
- In-reply-to: <2E889B52-A436-4081-8BA1-15520802E1B8@xxxxxxxxxxxxxxxxxx>
- Mail-followup-to: William Scott <wgscott@xxxxxxxxxxxxxxxxxx>, zsh-users@xxxxxxxxxx
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <2E889B52-A436-4081-8BA1-15520802E1B8@xxxxxxxxxxxxxxxxxx>
On 2008-07-09 at 10:05 -0700, William Scott wrote:
> If, while in zsh, I type
>
> source /whole/path/to/sourcefile
>
> and have dirname $0 embedded within the sourcefile
>
> In zsh, it will report back the full directory path for the directory
> in which this file is located, the same way it does for shell scripts.
>
> In bash, I just get the location of the bash executable itself.
>
> Is there an equivalent command that will work in bash (or preferably
> both shells)?
Both shells:
dirname ${BASH_SOURCE:-$0}
In bash, BASH_SOURCE is an array variable but referring to an array gets
you the first element only (unless you explicitly expand the array), so
you have the value. In zsh, unless you've got something exporting
BASH_SOURCE to the environment,the variable will be unset, so you get
the default value, $0 which should give you the same thing.
Phil
Messages sorted by:
Reverse Date,
Date,
Thread,
Author