help-bash
[Top][All Lists]
Advanced

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

Re: small problem with BASH_SOURCE and PATH


From: Alex fxmbsw7 Ratchev
Subject: Re: small problem with BASH_SOURCE and PATH
Date: Sat, 12 Feb 2022 15:40:35 +0100

the 'in which my script is in' dir name

if [[ $BASH_SOURCE == */* ]] ; then cd "${BASH_SOURCE%/*}" ; fi
name=${PWD%/*}

On Sat, Feb 12, 2022 at 2:51 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:

>
>
> On Sat, Feb 12, 2022 at 2:47 PM Greg Wooledge <greg@wooledge.org> wrote:
>
>> On Sat, Feb 12, 2022 at 08:59:12AM +0100, Alex fxmbsw7 Ratchev wrote:
>> > On Fri, Feb 11, 2022 at 11:42 PM Greg Wooledge <greg@wooledge.org>
>> wrote:
>> > > Clearly Lhunath intended this code to be used only when running the
>> > > script as a command, e.g. "myscript", not by typing "bash myscript".
>> > > If you'd like to edit the page to make that clear, go ahead.  As I
>> > > said, it's a publically writable wiki.
>> >
>> > correction, its made when "./script" or "bash ./script"
>> > if its not the slash to remove is missing and the case isnt covered by
>> if
>> > so it fails
>>
>> Incorrect.
>>
>> unicorn:~$ vi bin/xmb
>> unicorn:~$ chmod +x bin/xmb
>> unicorn:~$ cat bin/xmb
>> #!/bin/bash
>> declare -p BASH_SOURCE
>> unicorn:~$ xmb
>> declare -a BASH_SOURCE=([0]="/home/greg/bin/xmb")
>>
>> When invoked as a command through the shebang mechanism, you get a
>> path with slashes in it.  The *only* time it fails is when you explicitly
>> type "bash scriptname".
>>
>
> this case i meant
>
>
>> It would be nice if you would take 2 minutes to test these things
>> yourself, rather than spouting ignorance.
>>
>
> i got it all, now, with help, we aint at the beginning where i was failing
> with headpain and such
> i also wanted to edit, but since i got banned off #bash for not talking
> bash but including bash in every msg and ignorance to not unban me i left
> irc so no botwikicode
>
> a valid where my path is is at least an [[ $BASH_SOURCE != */* ]] check
> a another one if u dont cd like me to the dir but absolute path it, == /*
> || prefix $PWD
> in less code u cant do it and see it results in a cmd err
>
> in the major bash script case
>


reply via email to

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