Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create a script to find a random word from a dictionary

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading