Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can someone help me understand this script? It is from sysconf_add and I am new to scripting.
I need to do something similar.

function add_word() {  
    local word=$1  
    local word_quoted=$2  
    if ! word_present; then  
        $debug && cp $file $tmpf  
        sed -i -e "${lineno} {   
            s/^[[:space:]]*\($var=\".*\)\(\".*\)/\1 $word_quoted\2/;   
            s/=\" /=\"/   
            }" $file  
        $debug && diff -u $tmpf $file  
        echo \"$word\" already present  
    # some balancing for vim"s syntax highlighting  
share|improve this question
Maybe ask a more specific question? Which line you do not understand ? Also, you should give complete references (What is sysconf_add? What operating system? What shell does it uses?). –  vladmihaisima Oct 22 '12 at 9:14
@vladmihaisima:I am interested in sed.I don't really know what is…. I think it is for apache –  Jim Oct 22 '12 at 9:20

1 Answer 1

This is a good resource for sed

For your example above:

  • The -i flag means 'edit in-place' (GNU sed only), this is editing $file in-place
  • The -e flag chains together multiple commands.
  • The first command in your example looks to be replacing instances of $var="<stuff>" with the second argument passed to the script.
  • The second command removes trailing space following the sequence =" (e.g. foo=" bar " would become foo="bar ")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.