We’ve discussed the topic of Linux (or unix) shell scripting method of global file substitutions with the very old Are you interested in combating drudgery? and the example usage in str_replace.sh
Yesterday we revisited the idea regarding the upgrade to PHP 5.4 recently, and its affect on the osCommerce sample data website we have here at the www.rjmprogramming.com.au domain.
This PHP: Deprecated features in PHP 5.3.x – Manual link outlines some of the issues we tackled using global substitution methods.
So, with these deprecated features in mind we came up with the Korn Shell scripting code you could call oscommerce.ksh as you can see below …
#!/bin/ksh
# oscommerce.ksh
# Changes to osCommerce code to fix for PHP 5.4 ...
# PHP: Deprecated features in PHP 5.3.x - Manual
# http://php.net/manual/en/migration53.deprecated.php
if [ ! -z "$1" ]; then
files=$(grep -rl HTTP_POST_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_POST_VARS/_POST/g'
files=$(grep -rl HTTP_COOKIE_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_COOKIE_VARS/_COOKIE/g'
files=$(grep -rl HTTP_GET_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_GET_VARS/_POST/g'
files=$(grep -rl HTTP_SERVER_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_SERVER_VARS/_SERVER/g'
files=$(grep -rl HTTP_ENV_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_ENV_VARS/_ENV/g'
files=$(grep -rl HTTP_SESSION_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_SESSION_VARS/_SESSION/g'
files=$(grep -rl HTTP_POST_FILES ${1}) && echo $files | xargs sed -i 's/HTTP_POST_FILES/_FILES/g'
files=$(grep -rl HTTP_REQUEST_VARS ${1}) && echo $files | xargs sed -i 's/HTTP_REQUEST_VARS/_REQUEST/g'
else
echo "Please add a path of interest"
fi
exit
… and we also include a version that would work for Mac OS X environments that have an additional parameter for sed shown with oscommerce_mac.ksh
Of great help with the ideas of this script was this link … thanks.
Below are links to information regarding some of the Linux commands used in the script …
… enjoy today’s tutorial, and hope to see you again soon.
If this was interesting you may be interested in this too.
13 Responses to Linux Global Substitutions Primer Tutorial