Article 53AGV [SOLVED] Shell script: Iterate through values in variable in for loop

[SOLVED] Shell script: Iterate through values in variable in for loop

by
ddenial
from LinuxQuestions.org on (#53AGV)
Hello All

I'm writing a shell script that does some video encoding based on extension type.

Here is my sample script:
Code:#!/bin/bash
shopt -s globstar
shopt -s nocaseglob
shopt -s nullglob

for FILE in **/*.mp4 **/*.avi **/*.mkv **/*.mov **/*.webm **/*.wmv **/*.flv **/*.mpg **/*.mpeg ; do
echo "$FILE"
doneHere is the output:
Code:$ ./hevc.sh
264.mp4
265.mp4But since I'll be using the for loop so many times, I want to keep extensions in variables. But unfortunately is not working.
Code:#!/bin/bash
shopt -s globstar
shopt -s nocaseglob
shopt -s nullglob

EXTN="**/*.mp4 **/*.avi **/*.mkv **/*.mov **/*.webm **/*.wmv **/*.flv **/*.mpg **/*.mpeg"
for FILE in "$EXTN" ; do
echo "$FILE"
doneOutput:
Code:$ ./hevc.sh
**/*.mp4 **/*.avi **/*.mkv **/*.mov **/*.webm **/*.wmv **/*.flv **/*.mpg **/*.mpegHow do I make for loop treat every extension in variable as files rather than just print it?

Thankslatest?d=yIl2AUoC8zA latest?i=OUkQHafcaxA:Q44zRcZOn9g:F7zBnMy latest?i=OUkQHafcaxA:Q44zRcZOn9g:V_sGLiP latest?d=qj6IDK7rITs latest?i=OUkQHafcaxA:Q44zRcZOn9g:gIN9vFwOUkQHafcaxA
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments