help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: is there a difference between $BASH_SOURCE and $0 in portability ?


From: Alex fxmbsw7 Ratchev
Subject: Re: is there a difference between $BASH_SOURCE and $0 in portability ?
Date: Thu, 17 Feb 2022 01:14:33 +0100

On Thu, Feb 17, 2022 at 1:11 AM Jeffrey Walton <noloader@gmail.com> wrote:

> On Wed, Feb 16, 2022 at 5:38 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
> >
> > i ask cause BASH_ isnt maybe availabe, so i must use $0 to exec with new
> > bash again ( os x ) .. whats the difference .. ( of $0 vs BASH_SOURCE ) ?
>
> In practice, yes. When I test some of my scripts on really old Bash
> (like Fedora 1 or Ubuntu 4), BASH_SOURCE (builtin) has different
> behavior than assigning:
>
>     if [[ -z "$BASH_SOURCE" ]]; then
>         BASH_SOURCE=$0
>     fi
>
> I tried using the assignment because some of my scripts were meant to
> be sourced, and they did this:
>
> if [ ! -e "${ANDROID_TOOLCHAIN}/$CC" ]; then
>    echo "ERROR: Failed to find Android clang. Please edit this script."
>    [ "$0" = "${BASH_SOURCE[0]}" ] && exit 1 || return 1
> fi
>
> Jeff
>

ah cool now i remember, in source command its different

thank you


reply via email to

[Prev in Thread] Current Thread [Next in Thread]