Wednesday, February 2, 2022

[SOLVED] How to use Loop using lowriter command on shell

Issue

I'm tryingto execute lowriter command several times in a loop:

#!/bin/sh

ROOT_DIRECTORY="docs"

function count_files()
{
    ls -lR $ROOT_DIRECTORY/*.doc | wc -l
}

function get_number_folders()
{
    expr $(count_files) / 100 + 1
}

function create_folders_and_fill_with_files()
{
    for num in $(seq 1 $(get_number_folders))
    do
        #mkdir $ROOT_DIRECTORY/$num
        mv `ls $ROOT_DIRECTORY/*.doc | head -100` $ROOT_DIRECTORY/$num/
        convert_to_pdf $ROOT_DIRECTORY $num
    done
}

function convert_to_pdf()
{
    lowriter -convert-to pdf --outdir ./docs/ $1/$2/*.doc --headless
    set -x
}

create_folders_and_fill_with_files

Everything "works" fine, but the command was executed only one time.

How can I execute the lowriter command all times that for need.

Thankyou


Solution

I have solved my question adding 2>&1 in the end of the convertion line;

lowriter -convert-to pdf --outdir ./docs/ $1/$2/*.doc --headless 2>&1


Answered By - Hermus
Answer Checked By - Timothy Miller (WPSolving Admin)