PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Alternative to ksh/whence
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Alternative to ksh/whence

Réponse
 
LinkBack Outils de la discussion
Vieux 05/11/2007, 10h32   #1
Kenneth Brun Nielsen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Alternative to ksh/whence

At my work, we have a fancy tool setup. At some point a script (/bin/
sh -u) is run including the command:

progpath='/bin/ksh -c "whence $0"'

This command does not work. The problem is, that we do not use ksh at
this place (not installed, and I won't dare to try, unless you tell me
otherwise..). The context of the command clearly reveals the intention
of it, i.e. to get the path of the run script.

Do you guys know an alternative command (available in sh/csh/bash)?
I'd prefer not to code an absolute path into the script...

Best regards,
Kenneth

  Réponse avec citation
Vieux 05/11/2007, 11h03   #2
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Alternative to ksh/whence

2007-11-05, 10:32(-00), Kenneth Brun Nielsen:
> At my work, we have a fancy tool setup. At some point a script (/bin/
> sh -u) is run including the command:
>
> progpath='/bin/ksh -c "whence $0"'
>
> This command does not work. The problem is, that we do not use ksh at
> this place (not installed, and I won't dare to try, unless you tell me
> otherwise..). The context of the command clearly reveals the intention
> of it, i.e. to get the path of the run script.

[...]

But is not correct. $0 shouldn't be looked up in $PATH unless it
can't be found in the current directory.

If your /bin/sh is a Unix conformant shell, try:

progpath=$(
progpath=$0
case $0 in
(*/*) ;; (*)
[ -e "$progpath" ] || progpath=$(command -v -- "$progpath") || exit
esac
cd -P -- "$(dirname -- "$progpath")" && pwd -P || exit
) || exit
progpath=$progpath/$(basename -- "$0")

The above doesn't work if the dirname or basename of $0 ends in
a newline character.

--
Stéphane
  Réponse avec citation
Vieux 06/11/2007, 16h27   #3
Kenneth Brun Nielsen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Alternative to ksh/whence

On Nov 5, 12:03 pm, Stephane CHAZELAS <this.addr...@is.invalid> wrote:

> If your /bin/sh is a Unix conformant shell, try:
>
> progpath=$(
> progpath=$0
> case $0 in
> (*/*) ;; (*)
> [ -e "$progpath" ] || progpath=$(command -v -- "$progpath") || exit
> esac
> cd -P -- "$(dirname -- "$progpath")" && pwd -P || exit
> ) || exit
> progpath=$progpath/$(basename -- "$0")
>
> The above doesn't work if the dirname or basename of $0 ends in
> a newline character.


Thanks mate. I will implement this and hope it works. Thanks for your
effort - it's appreciated

/Kenneth

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h43.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,12684 seconds with 11 queries