Page 1 of 1
[SOLVED] $1 for post-proc scripts on Linux has no value
Posted: February 10th, 2013, 11:29 pm
by ericab
as the topic says;
$1 for post-proc scripts on Linux has no value.
i couldn't figure out why my post proc script (which cleans up some junk files for TV *only*, ie; nfo, srr, url, txt, etc etc... ---- note this is why im not using the built in junk cleaner) would not remove junk anymore.
to verify this; i added a simple "echo $1" in my script, and after a show had downloaded, i checked the script log.
there was no echo of its value.
anyone else see this as well ?
**edit
i should note that that behavior surface on either 0.7.10, or 0.7.11
**edit 2
it seems $5 also has no value
Re: $1 for post-proc scripts on Linux has no value anymore
Posted: February 12th, 2013, 1:51 pm
by shypike
Did you test with the sample script in SABnzbd's distribution?
What does that give.
Listing the script here (Sample-PostProc.sh):
Code: Select all
#!/bin/sh
# Example of a post processing script for SABnzbd
echo
echo Started as $0
echo
echo "The first parameter (result-dir) =" "$1"
echo "The second parameter (nzb-name) =" "$2"
echo "The third parameter (nice name) =" "$3"
echo "The fourth parameter (newzbin-id) =" "$4"
echo "The fifth parameter (category) =" "$5"
echo "The sixth parameter (group) =" "$6"
echo "The seventh parameter (status) =" "$7"
echo
Re: $1 for post-proc scripts on Linux has no value anymore
Posted: February 12th, 2013, 2:35 pm
by ericab
i ran post-proc with that script and it works !
this is what i get:
Started as /home/eric/Dropbox/Code/Scripts/SABnzbd/sample
The first parameter (result-dir) = /home/eric/_Downloads/_TV/American Dad/s08
The second parameter (nzb-name) = American.Dad.S08E11.HDTV.x264-LOL.nzb
The third parameter (nice name) = American_Dad_S08E11_HDTV_x264-LOL
The fourth parameter (newzbin-id) =
The fifth parameter (category) = tv
The sixth parameter (group) = alt.binaries.teevee
The seventh parameter (status) = 0
now when i download the same file, with my script, (here is really simple junk remover script btw)
GARBAGE=".nfo .sfv .srt .srr .url .txt"
echo
for junk in $GARBAGE
do
echo "Removing: $junk"
find "$1" -name *$junk -type f -exec rm -f {} \;
done
i get this:
Removing: .nfo
find: cannot search `': No such file or directory
Removing: .sfv
find: cannot search `': No such file or directory
Removing: .srt
find: cannot search `': No such file or directory
Removing: .srr
find: cannot search `': No such file or directory
Removing: .url
find: cannot search `': No such file or directory
Removing: .txt
find: cannot search `': No such file or directory
\o/
Re: $1 for post-proc scripts on Linux has no value anymore
Posted: February 12th, 2013, 2:52 pm
by ericab
i think ive figured it out;
not sure why this happens, my bash script i posted above, is contained within a function.
if i remove it as a function, all works as it should.
Re: $1 for post-proc scripts on Linux has no value anymore
Posted: February 12th, 2013, 4:47 pm
by jcfp
That's expected, see bash reference manual.
When a function is executed, the arguments to the function become the positional parameters during its execution (see Positional Parameters). The special parameter ‘#’ that expands to the number of positional parameters is updated to reflect the change. Special parameter 0 is unchanged. The first element of the FUNCNAME variable is set to the name of the function while the function is executing.
So you can't reference the global script arguments as $1 (etc.) in a function. Either pass those params to the function, or create regular vars out of them and use those inside the function.
Re: $1 for post-proc scripts on Linux has no value anymore
Posted: February 12th, 2013, 7:51 pm
by ericab
thanks jcfp @ shypike