I tried to write a script in order to automate the switching between php5.3 and 5.4 in my path. Although the export works when I execute it, it does nothing when it runs inside the script.
Here is my script
#!/bin/bash
# chphp
# Switch between php versions 5.3 and 5.4
FIXED_PATH=/here/is/my/path
if [ "$1" != "-v" ]
then
echo "Wrong usage of the script.\n"
else
if [ "$2" == 3 ]
then
export PATH="$FIXED_PATH:/path/to/php-5.3/bin"
export PHP_INI_SCAN_DIR=""
elif [ "$2" == 4 ]
then
export PATH="$FIXED_PATH:/path/to/php-5.4/bin"
export PHP_INI_SCAN_DIR="/path/to/php-5.4/etc/php-dbg.d"
else
echo "Wrong usage of the script.\n"
fi
fi
I also tried the following, which I found by searching for similar questions, but they didn't work
this
. ./chphp.sh -v 3
and this
source ./chphp.sh -v 3
Any suggestions or ideas how I could fix it or do things differently?
EDIT: The code was missing an else after the first echo, as Kent noticed and which I edited. The code now runs with both ways now!