Skip to Content
Linux Shell Scripting Cookbook - Third Edition
book

Linux Shell Scripting Cookbook - Third Edition

by Clif Flynt, Sarath Lakshman, Shantanu Tushar
May 2017
Beginner
552 pages
28h 47m
English
Packt Publishing
Content preview from Linux Shell Scripting Cookbook - Third Edition

How to do it...

This script will display a word definition:

#!/bin/bash 
#Filename: define.sh 
#Desc: A script to fetch definitions from dictionaryapi.com 

key=YOUR_API_KEY_HERE 

if  [ $# -ne 2 ]; 
then 
  echo -e "Usage: $0 WORD NUMBER" 
  exit -1; 
fi 

curl --silent \
http://www.dictionaryapi.com/api/v1/references/learners/xml/$1?key=$key | \ 
  grep -o \<dt\>.*\</dt\> | \ 
  sed 's$</*[a-z]*>$$g' | \ 
  head -n $2 | nl 

Run the script like this:

    $ ./define.sh usb 1
    1  :a system for connecting a computer to another device (such as   
    a printer, keyboard, or mouse) by using a special kind of cord a   
    USB cable/port USB is an abbreviation of "Universal Serial Bus."How 
    it works...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Linux Shell Scripting - Second Edition

Mastering Linux Shell Scripting - Second Edition

Mokhtar Ebrahim, Andrew Mallett

Publisher Resources

ISBN: 9781785881985