Matej Cepl wrote: > Comments?
I can't comment on the ability of the script to do the task you set it, but here's some comments on the script itself: Isn't "function" a bash-ism? You can just use "lyxvalue" here. function lyxvalue() You should enclose $2 in double quotes. It might contain spaces. STRING=$(grep "^\\\\$1" $(basename $2 .sgml).lyx) Some explanation of what the function does wouldn't help... Quote $1 and $OUTPUT: lyxvalue inputencoding $1 lenc2enc $OUTPUT While we're at it, I think you should quote all of your $FOO because they all derive from the input arguments. Your sed script might be a little more readable if you used single quotes rather than double quotes. Using multiple -e commands to a single sed is much more efficent than multiple invocations of sed. Finally, I do believe you're guilty of a "useless use of cat". Does this not do what you want? | sed -e '1c\ <?xml version="1.0" encoding="utf-8"?>\ <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"\ "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [\ <!ENTITY nbsp " ">\ <!ENTITY lsqb "‚">\ <!ENTITY rsqb "‘">\ <!ENTITY ldquo "„">\ <!--ENTITY rdquo "”"-->\ <!ENTITY lcub "{">\ <!ENTITY rcub "}">\ <!ENTITY dollar "$">\ <!ENTITY ellipsis "…">\ ]>\ \ ' \ -e '/^\s*$/d' \ -e 's/\s*\n\s*<\//<\//' Having said that, '\s' is a GNU-ism anyway. If you want others to use your script, use [ TAB] where TAB is a tab character. Your final s-command might be more readable if you used different delimiters. Eg s@@@ rather than s/// : [EMAIL PROTECTED]</@</@ Now that I've done that, I don't believe that the command does anything anyway. Your sed script is only acting on a single line of data. It'll never see a '\n' character. Try 's/[ TAB]\{1,\}$//; s/^[ TAB]\{1,\}//'. Ie, strip redundant whitespace from the end of lines and the beginning of lines. Right? If you move the '/^[ TAB]*$/d' command after the whitespace stripping one, you'll remove all empty lines... Best, -- Angus