Not signed in (Sign In)

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthoraef110
    • CommentTimeJan 6th 2012
     
    Hello,

    Can anyone provide a basic sample script intended to be run after the web exporter is used?

    I've tried this:

    #!/bin/sh
    cd "$EXPORT_PATH"

    for file in $WRITTEN_FILES
    do
    python ulysses.py "$file"
    done


    It returns with error status 1, and zero output is generated. The Python script cleans up the HTML output, and it works as desired. (I did put the full system path to the Python script in the Bash script.)

    I've also made both the Bash script and the Python script executable (chmod 755).

    I'm sure it's just a simple syntactical matter—any help would be much appreciated.


    Many thanks,

    Albert
    •  
      CommentAuthoraef110
    • CommentTimeJan 6th 2012
     
    I've tried putting all the variable in double quotes, and then I get error status 2.
    •  
      CommentAuthorgoetz
    • CommentTimeJan 8th 2012 edited
     

    Your bash scripts looks almost correct, there's just one small caveat in bash. In bash, elements of an array (such as $WRITTEN_FILES) are separated using a variable called $IFS (internal field separator), which is set to whitespace (space, tab, and newline). Thus, all files which include a space are split. Thus, you need to set the IFS environment variable to line breaks only (see code) and reset it later (our own post-processing scripts do this already). The code also includes two lines which remove empty paragraphs (the line with the sed and the mv afterwards), which may look really nerdy but is the easiest way to do it.

    #!/bin/bash
    
    # Change to export directory.
        cd "$EXPORT_PATH"
    
    # Save field separator, set field separator to line breaks.
    SAVEIFS=$IFS
    IFS=$(echo -en "\n\b")
    
    # Iterate over all exported files.
    for FILE in $WRITTEN_FILES
    do
        echo "$FILE"
        # Delete empty paragraphs, write to temporary file. 
        sed '/\<p\>[ \t]*\<\/p\>$/d' "$FILE" > "$FILE".old
        # Move temporary file to original file.
        mv "$FILE".old "$FILE"
    done
    
    # Restore field separator.
    IFS=$SAVE_IFS