---
title: "Shell获取当前路径"
author: "wingware"
date: "2012-10-21T11:38:47Z"
tags: []
categories: ["编程语言"]
slug: "shell"
draft: false
lastmod: "2012-10-21T11:38:47Z"
id: 1702427
url: "https://wingware.iteye.com/blog/1702427"
---

```java
PRG="$0"

while [ -h "$prg" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

PRGDIR=`dirname "$PRG"`

[ -z "$catalina_home" ] && CATALINA_HOME=`cd "$PRGDIR/.." >/dev/null; pwd`


echo "catalina_home is $CATALINA_HOME";
```