Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to have a bash dictionary so I found gnome-dictionary. However, just typing gnome-dictionary will bring up a GUI box. In gnome-dictionary --help, and in the man file, it says a -n or --no-window flag will disable the GUI popup and print the result on stdout. But this does not work. Instead, it says you should see the help for whatever cool things to do.

The man page refers to gnome-utils 2.13.4.

Edit

Some "extra material" to the accepted answer.

# for `.bz2`; for `.gz`, drop `j` for `z`
# create (`sudo mkdir -p ...`) path if not there
add-dict () {
  sudo tar -xvjf $1 -C /usr/share/stardict/dic
}

alias sd="sdcv"

wd () {
  sdcv $1 | /usr/bin/fold --spaces --width=73
}
share|improve this question
    
Do you care if the solution isn't gnome-dictionary or is that a have to have? –  slm Jul 15 '13 at 2:08
    
@slm: No, check out the comment when I started the bounty. I need this for the functionality which I describe, it doesn't matter who did it, in what suite it belongs, etc. –  Emanuel Berg Jul 15 '13 at 14:14
    
Saw the comment, just wanted to confirm it. –  slm Jul 15 '13 at 14:19
add comment

5 Answers

up vote 1 down vote accepted
+100

Offline

If you're OK with using something other than gnome-dictionary you can use StarDict, sdcv.

installation

$ sudo apt-get install sdcv

dictionaries

To install dictionaries you can select them from the following lists:

Once you've downloaded either a .gz or .bz2 tarball from sites provided above, you can install it with one of the following commands:

  • .gz

    $ sudo tar -xvzf downloaded.tar.gz -C /usr/share/stardict/dic
    
  • .bz2

    $ sudo tar -xvjf downloaded.tar.bz2 -C /usr/share/stardict/dic
    

So let's install the GNU Linux English-English Dictionary:

$ sudo tar -xvjf stardict-xfardic-gnu-linux-2.4.2.tar.bz2 -C /usr/share/stardict/dic
stardict-xfardic-gnu-linux-2.4.2/
stardict-xfardic-gnu-linux-2.4.2/xfardic-gnu-linux.dict.dz
stardict-xfardic-gnu-linux-2.4.2/xfardic-gnu-linux.ifo
stardict-xfardic-gnu-linux-2.4.2/xfardic-gnu-linux.idx

You can see what dictionaries you have installed with sdcv:

  • None installed

    $ sdcv -l
    Dictionary's name   Word count
    
  • One dictionary installed

    $ sdcv -l
    Dictionary's name   Word count
    GNU/Linux English-English Dictionary    16694
    

testing it out

$ sdcv Linux
Found 1 items, similar to Linux.
-->GNU/Linux English-English Dictionary
-->Linux

UNIX-compatible operating system (and kernel) designed with free software tools and ported to several hardware architectures. Linux was initially developed by Linus Torvalds in 1991. Linux is open source software (OSS) and aims to be a viable alternative to competing proprietary operating systems. From Redhat-9-Glossary http://www.tldp.org/LDP/Linux-Dictionary/

Online

I know you're looking for just an offline mode but thought I'd add this online option as well to the mix, just for completeness.

You can use the dict.org service from the command line to look up dictionary definitions using curl.

$ curl dict://dict.org/d:YourWord

lookup

For example, let's look up "help":

$ curl dict://dict.org/d:help
220 pan.alephnull.com dictd 1.12.0/rf on Linux 3.0.0-14-server <auth.mime> <19093903.13634.1373874819@pan.alephnull.com>
250 ok
150 3 definitions retrieved
151 "Help" gcide "The Collaborative International Dictionary of English v.0.48"
Help \Help\ (h[e^]lp), v. t. [imp. & p. p. {Helped} (h[e^]lpt)
   (Obs. imp. {Holp} (h[=o]lp), p. p. {Holpen} (h[=o]l"p'n)); p.
   pr. & vb. n. {Helping}.] [AS. helpan; akin to OS. helpan, D.
   helpen, G. helfen, OHG. helfan, Icel. hj[=a]lpa, Sw. hjelpa,
   Dan. hielpe, Goth. hilpan; cf. Lith. szelpti, and Skr. klp to
   be fitting.]

You'll also get several examples of it's usage:

1. To furnish with strength or means for the successful
   performance of any action or the attainment of any object;
   to aid; to assist; as, to help a man in his work; to help
   one to remember; -- the following infinitive is commonly
   used without to; as, "Help me scale yon balcony."
   --Longfellow.
   [1913 Webster]

2. To furnish with the means of deliverance from trouble; as,
   to help one in distress; to help one out of prison. "God
   help, poor souls, how idly do they talk!" --Shak.
   [1913 Webster]
...
...

You also get synonyms:

Syn: To aid; assist; succor; relieve; serve; support;
     sustain; befriend.

You also get proper usage:

Usage: To {Help}, {Aid}, {Assist}. These words all agree in
       the idea of affording relief or support to a person
       under difficulties. Help turns attention especially to
       ...
       ...

dictionaries

The dict.org site provides more than 77 dictionaries:

$ curl dict://dict.org/show:db

So you can look up against a different dictionary (Free Online Dictionary of Computing - FOLDOC):

$ curl dict://dict.org/d:help:foldoc

Or you can just query them all:

$ curl dict://dict.org/d:help:*

best match

Instead of looking up a specific word using the d: operator you can use the match operator instead, m::

$ curl dict://dict.org/m:help

You can change which matching strategy to use: (exact, prefix, suffix, or even soundex):

$ curl dict://dict.org/m:help::prefix 

You can list all the strategies with this command:

$ curl dict://dict.org/show:strat

For example:

$ curl dict://dict.org/m:help::prefix 
220 pan.alephnull.com dictd 1.12.0/rf on Linux 3.0.0-14-server <auth.mime> <19095008.15164.1373875483@pan.alephnull.com>
250 ok
152 13 matches found
gcide "Help"
gcide "Helped"
gcide "Helper"
gcide "Helpful"
gcide "Helpfully"
gcide "Helpfulness"
...
...

References

share|improve this answer
    
Get back to you, I have to print this, read it, and test it. –  Emanuel Berg Jul 15 '13 at 14:16
    
Works great - see the edit for some shorthands. –  Emanuel Berg Jul 15 '13 at 14:50
add comment

The version of gnome-dictionary on my machine has no version switch, nor does it have a --no-window switch listed under --help-all

The man page refers to gnome-utils v2.13.4 and does list the switch --no-window but when trying from console with appropriate switches it fails without DISPLAY.

Perusing the source it's clear there is no longer a console option and the documentation is out of date.
Gnome is a fast moving target at present.

share|improve this answer
add comment

Not really an answer to gnome-dictionary not providing no-window option, but an alternative approach would be, to use lynx, and get the reference definition from reference.com on internet.

#!/bin/sh 
lynx -dump -nolist -pseudo_inlines                \
  'http://dictionary.reference.com/search?q='$1'&r=67'  \
  | tail -n +13 | less -r

There are other similar approaches/examples at http://baldwinsoftware.com/wiki/pmwiki.php?n=Main.Bashsearch

Take a look.

share|improve this answer
add comment

In Debian there are dict-gcide (1913 dictionary) and dict-wn (WordNet), which need a dictionary server (dictd or dicod), of which there is a client for Emacs. WordNet seems reasonable, you can test it at dict.org. I was a bit disappointed because I couldn't find the first word I searched for ("flabbergasting"), but maybe that was bad luck.

share|improve this answer
add comment

Since I posted this question so long ago, I've found Emacs' W3M and M-x dictionary mode. Although not exactly gnome-dictionary for the CLI, I thought I'd share two interfaces here as they invoke the modules to do exactly what I wished for: a CL interface to a dictionary (actually, dictionaries).

(defun lookup-word (wrd)
  "Look up a word in Wiktionary with `w3m'."
  (interactive
   (list
    (read-string
     (format "lookup word (%s): "  (thing-at-point 'word))
     nil nil (thing-at-point 'word)) ))
  (w3m (format "http://en.wiktionary.org/wiki/%s" (downcase wrd))) )

(defun dict (wrd)
  "Look up WRD with `dictionary'."
  (interactive
   (list
    (read-string
     (format "lookup word (%s): " (thing-at-point 'word))
     nil nil (thing-at-point 'word) )))  
  (dictionary-search wrd dictionary-default-dictionary) )
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.