I need to execute the following shell script in my macOS terminal. The loop never executes more than its first iteration.
function execute_function() {
# Launch job
number_of_jobs=$1
echo "Launching ${number_of_jobs} jobs"
for i in {1..$1}; do
job_id=`head /dev/urandom | tr -dc A-Z0-9 | head -c 6 ; echo ''`
echo "Launching Job: $job_id"
echo $i
done
}
When I run it, I always get:
execute_function 10
Launching 10 jobs
Launching Job: XX9BWC
{1..10}
The same happens if I replace: $1
with $number_of_jobs
or "${number_of_jobs}"
#!/bin/zsh
as first line. (you may need to check the path. – ctrl-alt-delor Apr 02 '19 at 07:57#!/usr/bin/env zsh
? – Jakub Jindra Apr 02 '19 at 08:46zsh
is/bin/zsh
on macOS. Obviously, you may want to useenv
if you need to use a 3rd-party installation ofzsh
. However, this is not the essence of this particular question. – Kusalananda Apr 02 '19 at 08:50