I have a shell script:
#!/bin/bash
for name in /home/imp/imp/msgs/$1.PK1; do
mv "$name" "${name%.PK1}.BRD" 2>/dev/null >/dev/null
done
for name in /home/imp/imp/msgs/$1.PK2; do
mv "$name" "${name%.PK2}.MIX" 2>/dev/null >/dev/null
done
It works, but only on pre-existing files. What happens, is that more *.PK1
and *.PK2
are created after the initial scan. I'd like this script to "loop"
and rename the files that are created afterwards. Is this possible?
UPDATE:
This is what I have now:
#!/bin/bash
while [ ! -z "$(ls *.PK1 *.PK2 2>/dev/null)" ]; do
for name in /home/imp/imp/msgs/$1.PK1; do
mv "$name" "${name%.PK1}.BRD" 2>/dev/null >/dev/null
done
for name in /home/imp/imp/msgs/$1.PK2; do
mv "$name" "${name%.PK2}.MIX" 2>/dev/null >/dev/null
done
sleep 1; done
Is that correct?
Thanks.
2>/dev/null >/dev/null
what is that. if you want to redirect stdout and stderr to /dev/null just use<command> > /dev/null 2>&1
– darvark Mar 24 '17 at 05:51.PK#
files? Why not place awhile true; do
andsleep 1; done
around your stuff? Adapt the sleep according to your expectations on how long it may take until new files will be renamed. But don't even think of removing it. – Philippos Mar 24 '17 at 06:01while true; do
and `sleep ;1' at? – ignatius Mar 24 '17 at 06:05while [ ! -z "$(ls *.PK1 *.PK2 2>/dev/null)" ]; do
at? – ignatius Mar 24 '17 at 06:11*.PK1
and*.PK2
files. – ignatius Mar 24 '17 at 08:13$1.PK1
and$1.PK2
to*.PK1
and*.PK2
, the problem is still that the script doesn't terminate. – ignatius Mar 24 '17 at 08:18ls
like that is very bad practice. See ikkachu's answer for a way to do it safely. – terdon Mar 24 '17 at 09:40