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.


Popular posts from this blog

Starting MongoDB Replica Set on Docker