I have a bash script that generates a vector of running Jobs on a cluster. Example:
Vector = [1.cluster 2.cluster 3.cluster]
I need to update this script to keep record of this Jobs. Normally I would do:
qstat jobnumber.cluster
My background is python and in python I could do something like:
map(qstat, Vector)
and this would return me a vector with the function return value for all vector entries. So the question is: Can I apply a function to a vector in bash and get a vector back?
Here’s the bash equivalent of the Pythonic code
result = [qstat(cluster) for cluster in Vector].If you’re using a bash array:
The difference between the two ways of appending to the array are that the first explicitly expands the array to add a new element, while the second creates a new array with the new element to add it to the end. That’s because bash doesn’t have an equivalent to Python’s
extendmethod.If you’re using an IFS-separated string: