pk a écrit : > Peng Yu wrote: > >> $0 gives the file name of the script. I could use several shell >> command to get the directory where the script is in. But I'm wondering >> if there is an easy-to-use variable that refers to the directory where >> the script is in? > > See this page: > > http://mywiki.wooledge.org/BashFAQ/028
This is well informed, very useful and very interesting page is considering the case where: - you want your widely distributed and very portable script to be called in any way from anywhere (including from a pipe from Mars). - hard-coding the location of your configuration files and libraries is not a problem. I am sure this is the most common case. But this is definitely not my case. Actually, my requirements are *the exact opposite*. For instance I do not want anyone to use my script but me. So I just do this instead: source $(dirname "$0")/functions.sh The fact that it might break whenever someone else uses my script in a way I did not plan is a feature (in this respect, this code is even too robust).