I need to run a command from python so I'm doing:
os.system('IFS=".";for f in data/* ; do read -ra ADDR <<< "$f"; mv "$f" "data/${ADDR[-1]}"; done;')
but it says :
sh: 1: Syntax error: redirection unexpected
But if I run this in bash it works fine:
IFS="."
for f in data/*
do
read -ra ADDR <<< "$f"
mv "$f" "data/${ADDR[-1]}"
done;
It works just fine. How can I fix it to work in one line?
@steeldriver has pinpointed the problem. You could solve it with:
but at this point, you're probably better just doing the whole thing in python instead of calling out to bash: something like
Following @steeldriver comment and @glenn jackman answers: