On Sun, 2 Nov 2003, Muli Ben-Yehuda wrote: > On Sun, Nov 02, 2003 at 09:01:55AM +0200, Shai Bentin wrote: > > > Here's the whole story. I have a java application which needs to start from > > the directory where it is as a working directory. The problem is that this > > application can be installed by the user anywhere on his system. So I need a > > way to start the application from the diectory it was saved in. In windows > > for example I can create a shortcut with a working directory, in Linux I > > don't know? One way is to use a script which I ask the user to set the > > working directory by him self. My question is if there are other ways to do > > it? > > untested, but should work, modulu error handling: > > APP=`which app` > DIR=`dirname $APP` > cd $DIR && echo $DIR && $APP
Unfortunately fails almost all the time, unless APP is something like X or Java or some huge other thing that has its own share in $PATH. Otherwise, perhaps you are trying a symlink is a public bin directory (/usr/bin) which points to your own bin (/usr/MyApp/bin). I probably would suggest (and actually use) this one: APP="myApp" BASEAPP=`\which "$APP" 2>/dev/null` BASEAPP=`readlink -f "$APP"` DIR=`dirname "$BASEAPP"` [ -n "$DIR" ] && cd "$DIR" "$APP" The backslash before app better be there (try which ls). [coded over-protectively] > etc ================================================================= To unsubscribe, send mail to [EMAIL PROTECTED] with the word "unsubscribe" in the message body, e.g., run the command echo unsubscribe | mail [EMAIL PROTECTED]