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!

3
  • your script expects 2 arguments, did you notice that? Commented Feb 6, 2013 at 16:23
  • Thanks for the comment, unfortunately I forgot to type it in the question. Now it is editied. Commented Feb 6, 2013 at 16:25
  • As @Kent noticed I had a mistake in my if statement. With the . ./chphp.sh -v 3 command it works now. Commented Feb 6, 2013 at 16:32

1 Answer 1

1

your script will set vars only if $1 is NOT -v

if $1 is -v, your script does nothing. check your script the first if-then

does this help? (to set php5.3 stuffs)

source ./chphp.sh foo 3
Sign up to request clarification or add additional context in comments.

1 Comment

You are right. I think that my eyes are tired. I was planning to put the part of code after the first echo in the else. Thanks for the help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.