[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?
Thanks


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?
Thanks