Monthly Archives: June 2013

How to run php inside a bash script


Yes…you CAN run a php script inside a bash script. (or any other programming language actually, inside a bash script). The syntax is shown below. Now I’m not sure that it’s always wise to do that, but it’s interesting that you can do that 🙂

I actually needed the output of a php script inside the bash script and didn’t want to have to rewrite the entire php script in bash, and didn’t want to rewrite the shell script in php, so I just decided to include the php script inside the bash script to make it quicker to complete. Worked like a charm. Thought I’d share the way I did that.

# Run php scripts inside bash

/usr/bin/php -q <<'EOF'

#call function here

Handbrake – my handy dandy .bashrc function

> type ripdvd
ripdvd is a function

ripdvd () 
    title=$(lsdvd -c | grep "Disc Title" | gawk '{print $3}');
    echo "The title is: $title";
    echo "Is this ok ? y/n: ";
    read answer;
    if [[ "$answer" == "n" ]]; then
        echo "Please give new name for the movie: ";
        read title;
    HandBrakeCLI -i /dev/cdrom -o ~/Movies/${title}.mp4 -e x264 -q 20.0 -a 1,1 -E faac,copy:ac3 -B 160,160 -6 dpl2,auto -R Auto,Auto -D 0.0,0.0 -f mp4 --detelecine --decomb --loose-anamorphic -m -O -x b-adapt=2:rc-lookahead=50