fortune — use the "fortune" program to display random saying


Attribute Pos. Req. Default Description
short Yes   0 Display only short (less than 160 characters) fortune sayings?
no-computer     0 Prevent display of computer-related fortunes?
a     1 Select random of all (potentially offensive) fortunes.
o     0 Select only offensive fortunes.
raw     0 Don't apply basic HTML formating to the text output from the fortune program?


The [fortune] tag calls the popular Unix fortune program to display random saying.

If no raw option is specified, basic HTML formatting is applied to the output (using the text2html Interchange filter).

The fortune program path defaults to /usr/games/fortune. You can override that by setting the MV_FORTUNE_COMMAND variable.

Any single-character option supported by the fortune program can be passed to this tag. See fortune manual page for more information.


This tag appears to be affected by, or affects, the following:
Global Variables: MV_FORTUNE_COMMAND


Example: Display short fortune saying

Put the following on your page:

[fortune 1]



fortune is available in Interchange versions:

4.6.0-5.9.0 (git-head)


Interchange 5.9.0:

Source: code/UserTag/fortune.tag
Lines: 57

# Copyright 2002-2007 Interchange Development Group and others
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.
# $Id: fortune.tag,v 1.7 2007-03-30 23:40:57 pajamian Exp $

UserTag fortune Order   short
UserTag fortune addAttr
UserTag fortune Version $Revision: 1.7 $
UserTag fortune Routine <<EOR
sub {
my ($short, $opt) = @_;
my $cmd = $Global::Variable->{MV_FORTUNE_COMMAND} || '/usr/games/fortune';
my @flags;
push @flags, '-s' if is_yes($short);
for(grep length($_) == 1, keys %$opt) {
push @flags, "-$_" if $opt->{$_};

if(is_yes($opt->{no_computer}) ) {
  push @flags, qw/
    6% education 
    6% food 
    6% humorists 
    6% kids 
    6% law 
    6% literature 
    6% love 
    6% medicine 
    6% people 
    6% pets 
    6% platitudes 
    6% politics 
    6% science 
    6% sports 
    6% work
    10% wisdom

my $out = '';
open(FORT, '-|') || exec ($cmd, @flags);

while (<FORT>) {
  $out .= $_

unless($opt->{raw}) {
  $out = filter_value('text2html', $out);
  $out =~ s/--(?!:.*--)/<br>--/s;
return $out;


Interchange Development Group


DocBook! Interchange!