0

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!

4

1 回答 1

1

$1仅当不是时,您的脚本才会设置vars -v

如果$1-v,您的脚本什么也不做。首先检查你的脚本if-then

这有帮助吗?(设置php5.3的东西)

source ./chphp.sh foo 3
于 2013-02-06T16:25:11.417 回答