LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-02-2021, 09:16 PM   #1
sofasurfer
Member
 
Registered: Oct 2003
Posts: 252

Rep: Reputation: 20
How do handle multi word files in a 'for' loop?


I know how to use parentheses in a ffmpeg command to increase volume on a multi word filename..
Code:
 $ ffmpeg -i "file.mp3" -filter:a "volume=4" "new file".mp3
But when it is inside of a loop where do I put the parentheses? Or do I have to edit all the filenames?

Code:
 $ for f in *.mp3; do   ffmpeg -i $f -filter:a "volume=4.5" louder/$f; done
I can't get it to read the names without failing.

Last edited by sofasurfer; 08-02-2021 at 10:42 PM.
 
Old 08-03-2021, 01:16 AM   #2
Michael Uplawski
Senior Member
 
Registered: Dec 2015
Posts: 1,624
Blog Entries: 40

Rep: Reputation: Disabled
Wrong:

Code:
#!/bin/bash

one="One Two One Two"
two="13 kleine Brötchen"
three="Homer Simpson"

for n in $one $two $three
do
  echo "$n"
done
Right:
Code:
#!/bin/bash

one="One Two One Two"
two="13 kleine Brötchen"
three="Homer Simpson"

for n in "$one" "$two" "$three"
do
  echo "$n"
done
PSE consider editing the topic of this thread: Multi-word filenames appears only in the text of the initial post.

Last edited by Michael Uplawski; 08-03-2021 at 01:18 AM.
 
1 members found this post helpful.
Old 08-03-2021, 01:46 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,118

Rep: Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369Reputation: 7369
It is all about quoting, not parenthesis.
I would suggest you to use shellcheck to analyze your script. It can definitely help you to handle "multi word filenames".
you can try something like this:
Code:
filelist=(*.mp3)
for n in "${filelist[@]}"
do
    echo ffmpeg -i "$n" ....
done
 
1 members found this post helpful.
Old 08-03-2021, 07:06 AM   #4
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,844

Rep: Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222
Quote:
Originally Posted by sofasurfer View Post
...
Code:
 $ for f in *.mp3; do   ffmpeg -i $f -filter:a "volume=4.5" louder/$f; done
I can't get it to read the names without failing.
The generated filenames by the *.mp3 are okay.
But in command arguments you must have $variables in quotes.

Code:
 $ for f in *.mp3; do   ffmpeg -i "$f" -filter:a "volume=4.5" "louder/$f"; done
or
Code:
 $ for f in *.mp3; do   ffmpeg -i "$f" -filter:a "volume=4.5" louder/"$f"; done
 
Old 08-04-2021, 05:33 PM   #5
sofasurfer
Member
 
Registered: Oct 2003
Posts: 252

Original Poster
Rep: Reputation: 20
Thanks for this info. And I really like shellcheck.com. Haven't figure it all out yet but I see how it will be a big help.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
regex for phrase like'word-word-word' Zero4 Linux - General 9 07-06-2019 06:36 AM
[SOLVED] what's the difference between a multi-cpu , multi-core and a multi-thread system ? entz Linux - Hardware 11 12-20-2011 04:49 PM
How can i read two files word by word at a time using any loop by shell script? vaibhavs17 Programming 16 03-19-2010 03:48 AM
word by word comparison in two files using loop in shell script vaibhavs17 Programming 2 03-05-2010 07:41 AM
ability to handle MS Word files Maidros Debian 3 03-17-2004 01:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:13 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration