سؤال

I couldn't really find a solution of my simple problem... Need your help. So..

I have two files:

  • run.sh:

    #!/bin/sh
    # include file my.sh
    . my.sh
    
  • my.sh:

    #!/bin/sh
    # Show my filename
    echo "$0"
    

And run command:

# sh run.sh

And result:

run.sh

But I'm expecting included filename:

my.sh

So the question is how to get CURRENT filename? Big thanks in advance!

هل كانت مفيدة؟

المحلول

In BASH you can use:

echo "${BASH_SOURCE[0]}"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top