Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of obtaining the real path of the current script by Linux

Shulou Source: shulou.com Published: 2022-06-02 04:18:36 10月03日 Update

1. Get the real path of the current script:

#! / bin/bashif [[$0 = ~ ^\ / .*] # determine whether the current script is an absolute path, and match all then script=$0else script=$ (pwd) / $0fiscript = `readlink-f $script` # starting with / to get the real path of the file script_path=$ {script%/*} # get the directory where the file is located realpath=$ (readlink-f $script_path) # get the real path of the directory echo $scriptecho $script_pathecho $realpath

2.readlink-f: get the real file location of the symbolic link, and finally get the real file location of the symbolic link

3.basename: gets the file name of the file

4.dirname: gets the directory name of the file

Summary

The above is the whole content of this article. I hope the content of this article has a certain reference and learning value for everyone's study or work. Thank you for your support. If you want to know more about it, please see the relevant links below.

Tags: File path content directory link script location location symbol learning value that is beginning file name more directory name article reference work support Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple vpn MariaDB Huawei