Page 1 of 1

"For loop" error in terminal with avconv

Posted: Mon Sep 04, 2017 2:48 pm
by Yotaphoner
Hi to all.

I want to convert many files their name beggin with 04 using avconv, but I am getting this syntax error:
bash: syntax error near unexpected argument 'do'
The script line is this :

Code: Select all

 sudo for i in 04*; do avconv -i "$i" -s:v hd480 -acodec mp3 "$i-480"; done 
I searched for examples of the "for loop" and it doesn't seem to be wrong. So no idea.

Thanks

Re: "For loop" error in terminal with avconv

Posted: Mon Sep 04, 2017 3:22 pm
by SurferTim
Correct use of for in a terminal.

Code: Select all

for((i=0;i<12;i++)); do echo "Test $i"; done;

Re: "For loop" error in terminal with avconv

Posted: Mon Sep 04, 2017 3:28 pm
by RaTTuS
it will be the sudo bit
dont use sudo as you should have write permissions etc...

or do sudo bash -c "..."

Re: "For loop" error in terminal with avconv

Posted: Mon Sep 04, 2017 5:12 pm
by scruss
SurferTim wrote:
Mon Sep 04, 2017 3:22 pm
Correct use of for in a terminal.

Code: Select all

for((i=0;i<12;i++)); do echo "Test $i"; done;
Not if you're globbing filenames like the OP wanted to do. Apart from the sudo error, they had the syntax correct:

Code: Select all

for i in 04*; do avconv -i "$i" -s:v hd480 -acodec mp3 "$i-480"; done
In bash, you can do your range example with the shorter, simpler:

Code: Select all

for i in {0..11}; do echo "Test $i"; done
It also accepts alpha ranges like {a..m}, and does what you'd expect.

Re: "For loop" error in terminal with avconv

Posted: Mon Sep 04, 2017 10:32 pm
by Yotaphoner
RaTTus is right. It was so obvius... Shame on me! jaja

But I would swear I tryied it....

Any way, thanks to all