Ubuntu 10.04, Launcher, $PWD…

Nils Kassube kassube at gmx.net
Thu Dec 27 21:07:58 UTC 2012

Johnny Rosenberg wrote:
> I wrote a script for my wife, who still runs Ubuntu 10.04 (it's still
> supported, you know…). To make it easy to run the script, I created a
> launcher for her desktop, but it didn't work. The reason is that the
> script uses some files located in the same folder as the script
> itself. I thought that PWD is the location in which the script
> starts. The script works when started directly, but not when started
> from the launcher.
> The launcher is located at her desktop (~/Skrivbord – this is a
> Swedish setup). I changed the script to view the PWD variable, and
> it displayed ~/, NOT ~/Skrivbord and NOT the folder in which the
> script is located.
> Is there a way to get around this, except to hard code the path?

I suppose that the launcher has the PWD set to $HOME. Then it would call 
the script with its entire path and your script could read $0 to find 
out how it was called. As you are only interested in the path, you could 
use something like this:

folder="$(dirname $0)"


More information about the ubuntu-users mailing list