Register
It is currently Sat Dec 20, 2014 12:54 am

portable script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 1 post ] 
Author Message
 PostPosted: Tue May 17, 2005 8:24 pm   
Site Admin

Joined: Tue May 17, 2005 7:31 pm
Posts: 251
Location: Georgia
:: originally posted by gbussi ::
Quote:
Hello,

I am writing a bash script which I would like to be as portable as possible.
I require that bash version 2 is installed, but I DON'T want to require a fixed location for it.
The following wrapper should search bash in the current PATH and execute itself using it.
The only bug is that "bash something" first search "something" in the current directory,
and then in the current PATH. This can lead to some problem if a file with the same name
of the script itself exists in the current directory.

Any suggestion?
Any simpler way to solve this problem?
Do you know if this solution is REALLY portable on any system (a part from the bug I exposed)?

Thanks a lot!

Giovanni

#! /bin/sh
# PORTABILITY WRAPPER
# This part of the script is aimed to relaunch the script itself using a bash interpreter.
if test $# -eq 0
then
bash --noprofile --norc "$0" --this-is-bash
exit
elif test "$1" != --this-is-bash
then
bash --noprofile --norc "$0" --this-is-bash "$@"
exit
fi
shift
(( ${BASH_VERSINFO[0]} < 2 )) && { echo "$0: bash version 2 is required" ; exit 1 ; }
# END PORTABILITY WRAPPER
# The real script follows
# ...


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP