You are not logged in.

#1 2010-03-03 22:51:41

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

can't get a variable to execute in my bash script [SOLVED]

I am trying to figure out why I can't get a variable ($switches in the script below) to output correctly in my bash script but am at a loss to do so.  Calling the variable within the for loop results in a null value for it even though I have defined it.  The variable just needs to replace the -V 2 text in the commented line right above it.  It simply does not work.

How can I force my encode routine to read the vars in without redefining them within it?

#!/bin/bash

cores=4
switches="-V 2"

encode() {
for file; do
fileout=$(echo "$file" | sed s'/.wav//')
#lame -V 2 "$file" "$fileout".mp3; done
lame "$switches" "$file" "$fileout".mp3; done
}

export -f encode
find . -name '*.wav' -print0 | xargs -0 -n 1 -P $cores bash -c 'encode "$@"' --

Last edited by graysky (2010-03-03 23:29:33)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Online

#2 2010-03-03 23:05:47

raf_kig
Member
Registered: 2008-11-28
Posts: 143

Re: can't get a variable to execute in my bash script [SOLVED]

your encode part is running in a subshell, try export switches="-V 2"

Offline

#3 2010-03-03 23:28:51

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,600
Website

Re: can't get a variable to execute in my bash script [SOLVED]

OK!  I got it now, thanks!  The variables are defined in /etc/multilame.conf

#!/bin/bash

. /etc/multilame.conf

encode() {
. /etc/multilame.conf
for file; do
fileout=$(echo "$file" | sed s'/.wav//')
lame "$switches" "$file" "$fileout".mp3; done
}

export -f encode
find . -name '*.wav' -print0 | xargs -0 -n 1 -P $cores bash -c 'encode "$@"' --

Last edited by graysky (2010-03-03 23:29:15)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Online

Board footer

Powered by FluxBB