I am working on a script where I want to iterate between the numbers 1 to 15, but want it shown as 01 02 03 ... 13 14 15. Essentially what I am trying to do is add 15 users using the newusers command and using this script as < to the command. newusers needs to be in this format:

pw\_name:pw\_passwd:pw\_uid:pw\_gid:pw\_gecos:pw\_dir:pw\_shell

Basically, it should look like this when I run the script with arguments =

```
cstuser01:EzVlK9Je8JvfQump:1001:1001:CST8177 user:/home/cstuser01:/bin/bash
cstuser02:EsKOfvhgnWpiBT6c:1002:1002:CST8177 user:/home/cstuser02:/bin/bash
cstuser03:qzQuR5vRgxdzY6dq:1003:1003:CST8177 user:/home/cstuser03:/bin/bash

```

I got most of it working but I am getting the error below:

> 
> ./15users.sh: 57: ./15users.sh: Illegal number: 08
> 
> 
> 

Here is my script so far (I took out a couple sections with error checking) =

```
#!/bin/sh -u
PATH=/bin:/usr/bin ; export PATH
umask=022

#num=1 (this variable is needed depending on which loop I use below)
user=$prefix"user"
uid=1001
gid=$uid
home=/home/$user
shell=/bin/bash

#echo "pw_name:pw_passwd:pw_uid:pw_gid:pw_gecos:pw_dir:pw_shell"
#PASSWD=$(openssl rand -base64 12)

```

I originally had this but ran into a few problems:

```
while [ $NUM -le 15 ] ; do
       if [ $NUM -lt 10 ] ; then
               NUM=0$NUM
       fi
       echo "$USER$NUM:$(openssl rand -base64 12):$UID:$GID:$GECO:$HOME$NUM:$SHELL"
       UID=$(( UID + 1 ))
       GID=$(( GID + 1 ))
       NUM=$(( NUM + 1 ))
done

```

A friend of mine suggested this, it works perfectly fine. But I am trying to future proof this thing. What if I have a 100 or 1,000 users to add.

```
for NUM in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 ; do
       echo "$USER$NUM:$(openssl rand -base64 12):$UID:$GID:$GECO:$HOME$NUM:$SHELL"
done

```

This didn't work:

```
for num in {01..15} ; do
    i=09
    echo "$(( 10#$num + 1 ))"
    10
done

```

I then tried this getting a syntax error =

./15users.sh: 50: ./15users.sh: Syntax error: Bad for loop variable

```
for (( num=1; num<=15; num++ )) ; do
    printf "%02d\n" $num
done

```

I tried this as well but seq prints vertically not horizontally:

```
#iterate=$(seq -w 1 15)
for $iterate ; do
       echo "$user$num:$(openssl rand -base64 12):$uid:$gid:$geco:$home$num:$shell"
done

```