Bash script get current file path


















Doesn't work for me when I execute a script via a symlink. Is there a variant which will determine the fully-resolved script directory? Show 7 more comments. EDIT: Added quotation marks to handle space characters. Alex Reynolds Alex Reynolds Dimitre Radoulov Dimitre Radoulov It will only work with bash. Vlad's code is overquoted. Your second line has an extra double-quote character.

The overquoting was needed on older Solaris versions, which were still being used at the time of the original post. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back In the first step we calculate the path to the root of the project, the root of our git repository. In our case it is the parent directory of the "examples" directory, that is 2 steps above the "shell" directory so we call dirname 3 times. Once to get rid of the filename and then twice to move up the directory tre to the root of the project.

Then from there we can add the path of each file or directory relative to the root of the it working directory. Toggle navigation Code Maven. Prev Next. Written by Gabor Szabo. If you have any comments or questions, feel free to post them on the source of this page in GitHub. Source on GitHub. Save my name and email in this browser for the next time I comment. Notify me via e-mail if anyone answers my comment. Table of Contents. Related Posts.

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud Search for:.



0コメント

  • 1000 / 1000