Home > Blockchain >  Create a script to find a random word from a dictionary
Create a script to find a random word from a dictionary

Time:12-14

The task is to write a bash script to output a random word from a dictionary whose length is equal to the number supplied as the first command line argument.

I tried to use awk command but it wasn't help full. I am not able to pass argument in that.

CodePudding user response:

I am also doing this activity and I create one simple solution.

I create the script.

#!/bin/bash

awk "NR==$1 {print}" /usr/share/dict/words

Here if you want a random string then you have to run the script as per the below command from the terminal.

./test.sh $RANDOM

If you want the print any specific number string then you can run as per the below command from the terminal.

./test.sh 123
  • Related