0

I have a bash function i would like to bsub. It is recursively called when i try to source the script, but if i don't source the script it doesn't seem to recognize my function. How do I correctly call besub on a function within the same script file?

my_script(should print "12345"):

#! /bin/sh
function myFunct {
echo $1
}

bsub -q myQueue "source ./my_script; myFunct 12345"
prostock
  • 9,327
  • 19
  • 70
  • 118

2 Answers2

0

a.bash may look like this

#! /bin/bash

export input=$1
function myFunct {
echo "$input"
}

# This is if you want to call bsub outside the bash
#  Use bsub -q Queue `./a.bash 12345`

myFunct "$input"  


# Put bsub inside and call the script
# ./a.bash 12345

bsub -q myQueue `myFunct "$input"`  
iamauser
  • 11,119
  • 5
  • 34
  • 52
  • thx. how would it look if i wanted to call bsub within a.bash? i want to do this because i have a forloop in my actual code. – prostock Aug 19 '13 at 21:03
  • Instead of `myFunct "$input"` you can write `bsub -q Queue \`myFunct "$input"\``. Then execute as `./a.bash 12345` – iamauser Aug 19 '13 at 21:08
  • ..thx again..but it doesn't seem to be able to find myFunct. i tested it by replacing echo "$input" with 'mkdir myDir' and nothing gets created. any ideas? – prostock Aug 19 '13 at 21:30
  • Notice `$input` is the argument you have to provide to the script. Also check the permission of your script. Paste the error it shows when you execute the script. – iamauser Aug 19 '13 at 21:40
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35812/discussion-between-prostock-and-iamauser) – prostock Aug 20 '13 at 06:24
0

I've gotten it to work with

bsub [...] bash -rcfile my_script.sh -i -c "myFunct 12345"
Andreas Løve Selvik
  • 1,262
  • 16
  • 25