A
A
Alexey Yarkov2016-10-24 22:40:13
bash
Alexey Yarkov, 2016-10-24 22:40:13

How to wait for a for loop in a bash script?

Wrote a script for Nautilus that changes the encoding of selected files.
I want to display a notification after the end of the operation, but as far as I know, the loop is executed in a separate thread and the notification appears before it completes.
How to wait until the end of the loop?

#!/bin/bash

FROM=cp1251
TO=utf-8
ICONV="iconv -f $FROM -t $TO"

for file in [email protected]
do
  if [ -f $file ]; then
    tmpf="/tmp/${file}.bak"
    cp ${file} ${tmpf}
    $ICONV < ${tmpf} > ${file}
    rm ${tmpf}
  fi
done

# /usr/share/icons/hicolor/48x48/apps/
# Параметр -i  - имя иконки без расширения
notify-send -i ktip "Операция завершена!" "Кодировка файлов изменена на UTF-8"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-10-24
@sim3x

as far as I know the loop is executed in a separate thread
No

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question