Simple bash script

Install makepasswd

apt-get install makepasswd

makepasswd usage

makepasswd –chars=N, where N is the length you want the password to be generated.

The default –minchars is 8 and –maxchars is 10.

Objective make a short script to generate password using makepasswd program.


#randomly generate 8 character password with makepasswd.


if [ “$n” != “0” ]; then
/usr/bin/makepasswd –chars=$n
else echo “Zero not allowed”


root@bt:/home/passwd# ./ 10


Note: When comparing numerical values, quotation must be used to enclose the variable and the number. Number is treated as string. For bash script, if loop, while loop and other loop uses square brackets […..] and not (…..).

Bash user input argument:

$1 = first argument.

$2 = second argument.

$3 = third argument.

and so on and so forth.

Arguments example:


echo “first argument : $1”
echo “second argument : $2”
echo “third argument : $3”
echo “fourth argument : $4”


./ 100 200 300 400
first argument : 100
second argument : 200
third argument : 300
fourth argument : 400





One thought on “Simple bash script

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s