开发者

compare my current directory to a predefined directory in unix

I'm trying to write a small script that will install开发者_Go百科 extensions for the cms I currently use. However, when I ssh into my box, I don't want to always want to see if i am in the correct directory to install my extensions. Instead, I would like to just run a command and in that command it checks the current working directory and then compares the end of that directory to the one i predefine.

for example, I install my extensions in, you guessed it, the extensions folder. Say i run pwd and it spits out /home/site.com/not_extensions_directory/. Then the script would see that the current directory is not the extensions one so then I can kill the install and print out a warning.

An even better solution would be having the script detect that I am not in the correct directory and then give a user prompt for

would you like to switch to the "extensions" directory to continue installing (yes/no)?

what would the correct syntax be for doing this on a unix box (either solution)?


Put this at the top of your script. Replace /path/to/extensions with your extensions folder.

CURRENT_DIR="$( cd "$( dirname "$0" )" && pwd )"

if [ $CURRENT_DIR != /path/to/extensions ]; then
    echo "This script needs to be run from /path/to/extensions"
    exit 1
fi 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜