bash question - Help

This is a discussion on bash question - Help ; Considering the file #/bin/bash echo $(dirname $0) if executed, will print you the directory where this file is located. If you try to source this file , will print "/bin" (that is where bash usually is located ). Now , ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: bash question

  1. bash question

    Considering the file

    #/bin/bash
    echo $(dirname $0)

    if executed, will print you the directory where this file is located.

    If you try to source this file , will print "/bin" (that is where bash
    usually is located ).

    Now , is there a way to discover the full path of the sourced file, the
    argument to source ?


    Thank you.

  2. Re: bash question

    Florentin Ionescu wrote in
    newsIKdneTr3MyePQDcRVn-gQ@comcast.com:

    > Considering the file
    >
    > #/bin/bash
    > echo $(dirname $0)
    >
    > if executed, will print you the directory where this file is located.
    >
    > If you try to source this file , will print "/bin" (that is where bash
    > usually is located ).
    >
    > Now , is there a way to discover the full path of the sourced file, the
    > argument to source ?
    >
    >
    > Thank you.
    >


    #/bin/bash
    echo "$(dirname $0)/${0}"

  3. Re: bash question

    IANAL_VISTA wrote:
    > Florentin Ionescu wrote in
    > newsIKdneTr3MyePQDcRVn-gQ@comcast.com:
    >
    >
    >>Considering the file
    >>
    >>#/bin/bash
    >>echo $(dirname $0)
    >>
    >>if executed, will print you the directory where this file is located.
    >>
    >>If you try to source this file , will print "/bin" (that is where bash
    >>usually is located ).
    >>
    >>Now , is there a way to discover the full path of the sourced file, the
    >>argument to source ?
    >>
    >>
    >>Thank you.
    >>

    >
    >
    > #/bin/bash
    > echo "$(dirname $0)/${0}"

    Thank you for tip, but does not work on my machine :

    ~$ cat /tmp/b.sh
    dir=$(dirname $0)/${0}
    echo $dir > /tmp/f.txt

    ~$ cat /tmp/f.txt
    /bin//bin/bash

    What I am looking for is the last expression to be "/tmp" .

+ Reply to Thread