|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi,
I am writing a script and in order to run properly it needs to know where it is located, in order to be able to find its resources. It works fine, until the path has a space in it. I having a little trouble resolving the issue. #!/bin/sh cd `dirname "$0"` pwd java -cp lib/myjar.jar:lib/icu4j-3_8.jar osj.main.MainClass If at the route I have two folders: /Applications /Applications (Java) and my script is in the "Applications (Java)" folder, then I always end up in the Applications folder. At the same time if I call: dirname "/Applications (Java)/MyApp/myapp.sh" then this works as should. Can anyone suggest a solution to my problem? Andre |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Jan 7, 4:28 pm, Andre-John Mas <andrejohn....@gmail.com> wrote:
> Hi, > > I am writing a script and in order to run properly it needs to know > where it is located, in order to be able to find its resources. It > works fine, until the path has a space in it. I having a little > trouble resolving the issue. > > #!/bin/sh > > cd `dirname "$0"` > pwd > java -cp lib/myjar.jar:lib/icu4j-3_8.jar osj.main.MainClass > > If at the route I have two folders: > > /Applications > /Applications (Java) > > and my script is in the "Applications (Java)" folder, then I always > end up in the Applications folder. At the same time if I call: > > dirname "/Applications (Java)/MyApp/myapp.sh" > > then this works as should. > > Can anyone suggest a solution to my problem? > > Andre Never mind, solved the problem. The issue wasn't with dirname, but with cd since I was missing some quotes: #!/bin/sh cd "`dirname "$0"`" pwd java -cp lib/myjar.jar:lib/icu4j-3_8.jar osj.main.MainClass Andre |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Mon, 7 Jan 2008 13:28:09 -0800 (PST), Andre-John Mas wrote:
[...] > I am writing a script and in order to run properly it needs to know > where it is located, in order to be able to find its resources. It > works fine, until the path has a space in it. I having a little > trouble resolving the issue. > > #!/bin/sh Beware! #! /path/to/the/posix/sh -- or nothing at all. As on some systems, the POSIX sh is not in /bin and /bin/sh is the deprecated Bourne shell. > > cd `dirname "$0"` cd -P -- "$(dirname -- "$0")" It still won't work if the dirname of $0 ends in newline characters because of a flaw in shells design. -- Stephane |
|
![]() |
| Outils de la discussion | |
|
|