Help with distributing scripts

Hi,

I have written a series of BASH scripts that I have grouped together into a software package I distribute to other users in my field. The package consists of a "master script", which users modify to specify particular processing variables. Depending on the variables specified, and their values, certain sub-scripts are then called to process data files.

As I mentioned, I have made this package of scripts available to download. Many users have limited UNIX experience, and I have tried to make everything as simple as possible. However one problem I have had is how to simplify the "installation" process.

The problem arises from the fact that users will install the folder of scripts in different locations. Therefore references to the master script, and all the subscripts it calls, will likely differ from user to user. For example, to run the master script one User 1 may have to type:

~/Desktop/example_software/master_script.sh

while User 2 will have to type:

~/bin/example_software/master_script.sh

And to call the first sub-script User 1's master script will need the line:

~/Desktop/example_software/subscript_1.sh

while User 2's master script will need:

~/bin/example_software/master_script.sh

It is obviously impossible to personalize scripts for every user. Does anyone have any suggestions on how to get around this? Is it as simple as telling everyone to install the scripts in their home directory (~)? Would that cause problems?

Thanks for any help,
Mike

You could try calling e.g. subscript_1.sh like this from master_script.sh:

${0%/*}/subscript_1.sh

Hi Scrutinizer,

Thank you very much for your help.

How can I solve the problem that the master script's location will vary by user?

Hi msb65, Why would that be a problem? Do you mean the users would not understand how to call the master script?

Hi Scrutinizer,

You are right, I should have more faith in my users!

Do you mind explaining how the ${0%/*} syntax works?

Thank you very much.

Mike

Hi msb65,

$0 Expands to the name of the shell script as it was called on the command line. By using parameter expansion ${parameter%word} the smallest suffix pattern is removed. In this case everything after and including the last slash gets removed (/*), i.e. the name of the script itself. What remains is the absolute or relative path to the directory in which the scripts are located...

S.