Comment puis-je obtenir le répertoire dans lequel se trouve un fichier de script bash, lorsque ce fichier de script est inclus dans un autre (ce qui le rend différent de this question)?Obtenir le répertoire un fichier de script bash est dans
/script1.sh
. /dir2/script2.sh
/dir2/script2.sh
# echoes "/dir2"
echo whatevergetsthatdir
C'est le script que je suis en train de "réparer"
/etc/init.d/s ilvercar-gameserver (unique pour tous les cas)
#!/bin/bash
#
# /etc/rc.d/init.d/silvercar-gameserver
#
# Initscript for silvercar game server
#
# chkconfig: 2345 20 80
# description: lalalalala
#CONFIG
BIN=/opt/silvercar-gameserver # Want to get rid of this
CONF=/etc/opt/silvercar-gameserver
. /etc/init.d/functions
. $BIN/gameserver.sh.inc
exit 0
/opt/silvercar-gameserver/gameserver.sh.inc (pas à modifier pour chaque installation. est dans le svn)
# Meant to be included from a script in init.d
# Required input:
# CONF (e.g. /etc/opt/silvercarserver)
# -- Installation config (must provide JSVC, JAVA_HOME)
. $BIN/localconf.sh
# -- Instance config (must provide ASUSER, ASWORK)
. $CONF/conf.sh
PIDFILE=$ASWORK/running.pid
LOGDIR=$ASWORK/log
CLASS=tr.silvercar.gameserver.runner.DaemonGameServer
ARGS=$CONF
start() {
echo "Going to start Gameserver..."
export JAVA_HOME
cd $BIN
$JSVC -jvm server -procname silvercar-gameserver -pidfile $PIDFILE -user $ASUSER -outfile $LOGDIR/stdout -errfile $LOGDIR/stderr \
-cp `cat classpath` -Dlogroot=$LOGDIR $CLASS $ARGS
echo "Gameserver started!"
}
stop() {
echo "Going to stop Gameserver..."
$JSVC -stop -pidfile $PIDFILE $CLASS
echo "Gameserver stopped!"
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo "Usage: /etc/init.d/silvercar-gameserver {start|stop|restart}"
exit 1
;;
esac
Vous savez déjà le répertoire - il est/dir2. –
@Neil Mis à part le fait que l'exemple ci-dessus est, eh bien, juste un échantillon, je le sais, mais script2 ne le fait pas. –