Friday, June 17, 2011

Change file Modification Date from Perl

Today I had a task to change the modification date of file. In Linux it could be done using command:

touch -m -d "date" filename

But 'touch' command under Mac OS X has different parameters and after using the same command we will get error:

touch: illegal option -- d
usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file

Thursday, January 20, 2011

Using 'trim' PHP function in bash

Today during writing some scripts I had a need of using PHP function 'trim' in bash script.
This code gave me perfect results:


trim() { echo $1; }

echo ">>$(trim 'right side     ')<<"
echo ">>$(trim '     left side')<<"
echo ">>$(trim '     both sides     ')<<"

Of course, second part (with echo) was written to test different cases whether it works correctly. Solution found here.