Yotaphoner
Posts: 52
Joined: Fri Jun 09, 2017 3:11 pm

"For loop" error in terminal with avconv

Mon Sep 04, 2017 2:48 pm

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

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: "For loop" error in terminal with avconv

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;

User avatar
RaTTuS
Posts: 10559
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: "For loop" error in terminal with avconv

Mon Sep 04, 2017 3:28 pm

it will be the sudo bit
dont use sudo as you should have write permissions etc...

or do sudo bash -c "..."
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

User avatar
scruss
Posts: 3212
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: "For loop" error in terminal with avconv

Mon Sep 04, 2017 5:12 pm

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.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
Pronouns: he/him

Yotaphoner
Posts: 52
Joined: Fri Jun 09, 2017 3:11 pm

Re: "For loop" error in terminal with avconv

Mon Sep 04, 2017 10:32 pm

RaTTus is right. It was so obvius... Shame on me! jaja

But I would swear I tryied it....

Any way, thanks to all

Return to “Advanced users”