Steam for Linux > Limited Beta > Topic Details
ik Dec 17, 2012 @ 10:25am
Hint to improve the startup scripts
Both scripts /usr/bin/steam and Steam/ use similar code to obtain the directory where the script itself resides.
STEAMROOT=$(cd "${0%/*}" && echo $PWD)

There is a lengthy explanation what it does. The ${0} is the name of the program currently been executed, in the way it have been started by exec(). The %/* portion removes the filename, leaving only the directory. The `cd` then goes into that directory. After successful change to the directory, its full pathname is contained into the PWD variable and the `echo` commands outputs it to the STEAMROOT variable.

All nice and good, unless you try to start the script from the command line. (As I was doing while trying to make it work under my Slackware). The problem is that regular users can start programs without writing any path component in the program name, just by typing `` (instead of `./`).

This makes the `cd` return error then the "&&" portion (logical "AND") handles the error and does not execute the second operation - `echo $PWD`. As result the rest of script may do strange things.

For me replacing the "&&" with ";" improves the things (so both commands are separate and always executed).
I can't came with other cases where `cd` could fail, other than changing permission of a directory after the scrip is started but before the `cd` is executed.
Showing 1-1 of 1 comments
< >
Sage Dec 17, 2012 @ 12:32pm 
I would do something along the lines of `STEAMROOT=$(cd "${0%/*}" || /*zenity dialog with useful stuff such as $? , ${0} , and $PWD*/ && exit 1; echo $PWD)`
Showing 1-1 of 1 comments
< >
Per page: 15 30 50