Linux Global Substitutions Primer Tutorial
โœ‚๐Ÿƒ๐Ÿพโ€โ™€๏ธ๐Ÿƒ๐Ÿผโ€โ™‚๏ธ
๐Ÿ“–

Linux Global Substitutions Primer Tutorial

Linux Global Substitutions Primer Tutorial

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.

This entry was posted in eLearning, Operating System, Tutorials and tagged , , , , , , , , , . Bookmark the permalink.

13 Responses to Linux Global Substitutions Primer Tutorial

Leave a Reply

Your email address will not be published. Required fields are marked *