A linux shell script that can grab the pronunciation mp3 file of an input word.
You have installed grep
, curl
, sed
and head
in your system.
Simply run the following command to see the result:
$ chmod +x lookup.sh # give it exec permission
$ ./lookup.sh good
You'll get an mp3 file whose name is good.mp3 in the current path and you can play it.
If you want to make this script a system command, you can add it to the PATH env.
You can do it like this on your computer:
Make a directory:
$ mkdir ~/bin
Copy the script to the directory:
$ cp lookup.sh ~/bin
Add the following line to ~/.bashrc
or ~/.zshrc
(based on the shell you are using):
export PATH=$PATH:~/bin
Run the following command or restart your terminal:
$ source ~/.bashrc
If you are using zsh:
$ source ~/.zshrc
Now you can use this script globally:
$ lookup.sh test
Before you run the script globally, make sure you have given it exec permission with the command:
$ chmod +x lookup.sh
If you want to download the mp3 files to a specific path, you can change the script:
...
wget -O /path/to/your/folder/$1.mp3 $url 2> /dev/null
...
echo /path/to/your/folder/$1.mp3
Don't forget to create the folder for saving downloaded files before you run the script.