I want to use a file to store the current version number for a piece of customer software which can be used by a start-up script to run the binary in the correct directory.
For Example, if the run directory looks like this:
.
..
1.2.1
1.2.2
1.3.0
run.sh
current_version
And current_version contains:
1.2.2
I want run.sh to descend into 1.2.2 and run the program foo.
The current solution is this:
!#/bin/sh
version = `cat current_version`
cd $version
./foo
It works but is not very robust. It does not check for file existence, cannot cope with multiple lines, leading spaces, commented lines, blank files, etc.
What is the most survivable way to do this with either a shell or perl script?