0

I have setup a Crontab that executes the "find" command which then executes a shell script on each of it's arguments. At the very end of the first shell script is another "find" command which executes another shell script. My question: is there a way to carry over the original arguments from the first script to the second script? I basically just need the original file-path/file-name of the first script's arguments in order to perform some parameter expansion on and obtain some log files.

Here's the the basics of the script:

Crontab: find "some files" -exec /home/Conversion.sh {} \;

At the end of Conversion.sh: find "some files" -exec /home/Copy.sh {} \;

There's no way to accurately track the files after the Conversion.sh because I'm using "Filebot" on those arguments, which completely changes the file-name of each argument and hence why I must use the "find" command again at the end. Any help is always appreciated!

1 Answers1

0

Pass them explicitly:

find "some files" -exec /home/Copy.sh {} "$@" \;
chepner
  • 497,756
  • 71
  • 530
  • 681
  • 1
    Just make sure that you don't have a semicolon in any positional parameter, or a `+` in `$1`, or any `{}`, as that would really mess with `find`'s `-exec`. If the positional parameters come from user input (and filenames should be considered as user input), really perform a sanity check, as otherwise this is subject to arbitrary code execution. – gniourf_gniourf Oct 31 '15 at 15:56
  • 1
    I think the only problem would with be a parameter that is *just* a `;` or `+`, but that is an ugly problem to work around. – chepner Oct 31 '15 at 16:05
  • Yes, that's what I meant! (sorry if that wasn't clear enough). – gniourf_gniourf Oct 31 '15 at 16:08
  • Thank you for the suggestion! Would the sub-script (Copy.sh) still be able to expand the first positional parameter ($1) from the parent-script (Conversion.sh)? I was under the impression that positional parameters were exclusive to the shell the script was running in? If that is true, is it possible to permanently set the file-path/file-name as a variable that is accessible to both scripts? – alteredstate Nov 02 '15 at 17:27
  • You can create an exported variable in `Conversion.sh`, then have `Copy.sh` look for that in its environment. That's probably a better idea than passing the values as positional parameters. `export filepath=$1 filepath=$2; find "some files" -exec /home/Copy.sh {} \;`. – chepner Nov 02 '15 at 17:35