forked from lodi-g/phpvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phprun
executable file
·41 lines (31 loc) · 846 Bytes
/
phprun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/bash
scriptname=`basename $0`
usage() {
echo "Usage: `basename $scriptname` file [version]*."
echo "Version will be ${versions[0]} by default."
exit 0
}
error() {
echo "Version '$1' is not installed. Either install it or use one amongst these:"
phpvm ls php | tail -n +2
exit 1
}
phpvm &> /dev/null
if [ $? != 0 ]; then
echo "Please install phpvm first."
exit 1
fi
versions=( $(phpvm ls php | tail -n 1) )
[ -z $1 ] || [ $1 == "-h" ] && usage
[ ! -f "$1" ] && echo "$1: No such file." && exit 1
file=$1
[ ! -z "$2" ] && versions=()
for ((i = 2; i <= $#; i++)); do
versions+=(${!i})
phpvm bin php ${!i} &> /dev/null
[ $? != 0 ] && error "${!i}"
done
for version in "${versions[@]}"; do
echo "$scriptname: starting `basename $file` with PHP v$version" >&2
$(phpvm bin php "$version")/php "$file"
done