In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
To write shell scripts, you generally need to take the current directory of the script as the working directory. How to get the directory of the current script?
How to get the directory where the script is located in the execution script is divided into two cases:
If the script is executed under the current path of the script, then pwd directly obtains the absolute path. If the script is called from another directory, cd to the directory where the script is located first, and then obtain the absolute path where the script is located.
Here are two ways:
The first is slightly more cumbersome: if [ "` dirname "$0" `" = "" ]|| [ "` dirname "$0" `" = ". " ] ; then CURRENT_PATH="`pwd`"else cd ` dirname "$0" ` CURRENT_PATH="`pwd`" cd - > /dev/null 2>&1 #Return to previous directory fi
The second method:
if [ `echo $0 | grep -c "/"` -gt 0 ];then
cd ${0%/*}
fi
CURRENT_DIR="$(pwd)"
The third method:
RUN_PATH=$(cd $(dirname $0); pwd)
Recommend the third writing.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
NAME ls-list directory contentsSYNOPSIS ls [OPTION]... [FILE]... DES
© 2024 shulou.com SLNews company. All rights reserved.