0

I'm wondering how to call a multi-line IDL command from a shell script. For example, to call a one-line command idl_dummy.pro I can do:

idl -e "idl_dummy"

I have a set of codes that take more than one line to execute in IDL. Within IDL I need to run:

.comp /a_different_directory/idl_file.pro

ans = idl_dummy(123456)

How can I run this code from a shell script?

Community
  • 1
  • 1
Oak Nelson
  • 75
  • 11

2 Answers2

1

I usually do something like this

#!/bin/bash

read -r -d '' IDL_SCRIPT <<EOF
  .comp /a_different_directory/idl_dummy.pro

  ans = idl_dummy(123456)
  ; print, ans ;?
EOF

# Print the script out for debugging
echo "${IDL_SCRIPT}"
idl <<< "${IDL_SCRIPT}"

or

idl <<< \
  "!path = EXPAND_PATH('/a_different_directory/:' + !path) & \
  idl_dummy, 123456"

You might have to play around with !path to automatically compile the code you need. I'd also recommend naming the procedure so you don't have to manually compile with .comp (as I suggested in the answer).

sappjw
  • 373
  • 1
  • 14
0

Put your two commands in a file with a .pro extension, say test_batch.pro. This is a batch file; it cannot use begin/end blocks, but doesn't need any special syntax.

Then call IDL like:

$ idl path/to/test_batch.pro
mgalloy
  • 2,356
  • 1
  • 12
  • 10
  • Thanks for your response! If possible I'd love to avoid such a wrapper script, but if that's the best way to do it I guess I have no choice! – Oak Nelson Jan 29 '19 at 21:19