views:

35

answers:

3

I'm making a (bash) script for mass keyfile generation. I need the script to name the first generated keyfile "1", the next "2" and so on - So I need every filename to be the previous filename + 1. The script so far:

#!/bin/bash
#Files in directory
 dir=$(ls -U -l /home/user/keyfiles|wc -l)
 name=
#script
 target=/home/user/keyfiles/$name
 dd if=/dev/random of=$target bs=1024 count=5

As you see, I would like to add 1 to $dir and store it in $name, every time the script is run.

+2  A: 

Either of these will work:

name=$((dir + 1))
let name=dir+1
John Kugelman
or `let dir++` (or any of the others) and just use $dir.
roe
or even `name=$(($(ls -U -l /home/user/keyfiles|wc -l)+1)`
roe
A: 

Wow, thanks guys!

Jensen
A: 

with bash,

((dir++))

ghostdog74