I'm currently working on a script in which I want to use an array length as a conditional argument. I can get the length of the array like this:
myarr=$(squeue | grep cjones903 | awk '{print $3}' )
echo ${#myarr}
but this wont work because I need the length to be evaluated iteratively in order to continue when the length drops below a threshold.
I would like to be able to do this:
while [ length is > x] do;
sleep 60;
else:
${#arrayname[@]}in bash. You can iterate over an array withfor ((i = 0; i < ${#arrayname[@]}; i++)); do ...(where$i=0, 1, 2, ...) or withfor i in "${arrayname[@]}"; do...where ($i=element1, element2, ...) There is no need for a conditional.(squeue | grep cjones903 | awk '{print $3}' )iteratively. After it drops below a certain count, I want to be able to continue my loop.${#myarray[@]} > x. Now as written above,myarris a string variable, not an array, so the length would simply be${#myarr} > x. To makemyarran array, you would needmyarr=( $(squeue | grep cjones903 | awk '{print $3}' ) )${#myarr}it will compute the length at that point. If you give a fuller example showing what you are trying to do, I can most likely show you how or give you a definitive on whether it is possible. Oh, also, your comparison should use the-gtor-lt, etc. numeric comparisons.