Skip to content

Instantly share code, notes, and snippets.

@vanduc1102
Last active April 4, 2020 16:44
Show Gist options
  • Save vanduc1102/d08d91f02113dea97ed8f854b4600d3d to your computer and use it in GitHub Desktop.
Save vanduc1102/d08d91f02113dea97ed8f854b4600d3d to your computer and use it in GitHub Desktop.
convert file twit to php bash
#!/bin/bash
for file in *.twig;
do
output="${file//-/_}" # convert all - to _
output="${output/.twig/_php_output_array}" # convert .twig to _php_output_array
init_output="<?php\n\n\$${output} = array();\n/** \n"
return_output="\n*/\nreturn \$${output};"
file_content=$(cat $file)
echo "${init_output}\n$file_content\n${return_output}" > "$file";
done
for file in *.twig; do mv "$file" "${file/.twig/.php}"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment