Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xml handling in shell scripts #2

Open
DamienIrving opened this issue May 14, 2015 · 1 comment
Open

xml handling in shell scripts #2

DamienIrving opened this issue May 14, 2015 · 1 comment

Comments

@DamienIrving
Copy link
Contributor

Most of the scripts in the old cct repo have the following code block for dealing with a cdscan xml file:

# Check if input is an XML file
inbase=`basename $infile`
extn=`expr match "${inbase}" '.*\.\(.*\)'`
if [ $extn = 'xml' ] ; then
  tmp_in=$TMPDIR/xml_concat.$$.nc
  python ${CWSL_CTOOLS}/utils/xml_to_nc.py None $infile $tmp_in
  infile=$tmp_in
fi

As you can see I've inserted ${CWSL_CTOOLS} to make it compatible with the CWSL plugin, but I'm wondering what to do with $TMPDIR? The nino34.sh script uses $temp_dir which is defined as follows:

temp_dir=$(mktemp -d)
function cleanup {
    rm -rf $temp_dir
}
trap cleanup EXIT

Should I do the same?

@captainceramic
Copy link
Contributor

I like that method of using a temp directory and then trapping the exit to remove it
As for the XML checking, I don't really like it as I would prefer not to use the xml catalogues, but if we must I think that method works.
The only change I would make is a switch from using backticks to using the $() - i.e. using:

inbase=$(basename $infile)

instead of

inbase=`basename $infile`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants