Passphrase generator script
Note: I run it with ./generator.bash 4 &gt; x &amp;&amp; vim x so stdout is not printed to the terminal, but I'm not sure if this is neccessary. I'm thinking that somewhere terminal history could be stored.


I don't think this is necessary.
If anything, you might forget to remove x,
which could be a security risk.

Avoid seq

seq is not a standard tool, and a native alternative exists:

for ((i = 0; i &lt; n; i++)); do ...; done


Extract constants out of loops

This statement is executed in each iteration of the loop:


lines=$(cat $words | wc -l)



But the content of the $words file is likely constant,
so it's safe to compute this once, before entering the loop.

Unnecessary cat

The cat command is unnecessary with wc, it's better to redirect input:


lines=$(wc -l &lt; "$words")



Double-quote variables in command line arguments

Although the content of $words doesn't contain spaces,
as a good practice it's good to double-quote it when using as program arguments, for example instead of:


awk "NR==$line" $words



Write:

awk "NR==$line" "$words"


Arithmetic context

Instead of this:


line=$((random % lines))



You can write simpler:

((line = random % lines))