#!/bin/bash
FILE=./db.pl
function h {
echo "\
========================= Command Help =========================
Usage: a <rel> <tar1> <tar2> [non-dw]
rel: Relationships(f/l/pl/k/h/ph)
tar1: Target 1
tar2: Target 2
non-dw: Set any value to this if the relationship is not
double way
Usage: c <tar1> <tar2> [tar3] [tar4] ... [tarN]
Enter any names (at least 2) to create a compound relati
-onship. ONLY give names as parameters, script will prom
-t you to input relationship.
Usage: f <file>
Change working file (Default ./db.pl)"
}
function f {
if [[ -z $1 ]]
then
echo "Error: missing parameter"
return 1
else
echo "Working on $1"
FILE=$1
fi
}
function get_rel {
case $1 in
f|friend)
R="friend"
;;
l|love)
R="love"
;;
pl|possiblelove)
R="possiblelove"
;;
k|know)
R="definedknow"
;;
h|hate)
R="hate"
;;
ph|possiblehate)
R="possiblehate"
;;
*)
return 1;
;;
esac
echo $R
}
function a {
if [[ -z $1 || -z $2 || -z $3 ]]
then
echo "Error: missing parameters"
return 1;
fi
R=$(get_rel $1)
echo "$R($2,$3)." >> $FILE.tmp
if [[ -z $4 ]]
then
echo "$R($3,$2)." >> $FILE.tmp
fi
cat $FILE.tmp
cfm_write
}
function c {
if [[ -z $1 || -z $2 || -z $3 ]]
then
echo "Error: missing operator"
return 1;
fi
echo -n "Relationship: "; read rel;
R=$(get_rel $rel)
for tar1 in $*
do
for tar2 in $*
do
if [[ $tar1 != $tar2 ]]
then
echo "$R($tar1,$tar2)." >> $FILE.tmp
fi
done
done
cfm_write
}
function cfm_write {
cat $FILE.tmp
echo -n "Write to $FILE? [Y/n] "; read yn;
if [[ -z $yn ]]
then
yn="Y"
fi
case $yn in
y|yes|Y|Yes)
echo -n "Writing file... "
cat $FILE.tmp >> $FILE
echo "OK"
;;
*)
echo "Give up writing."
;;
esac
rm $FILE.tmp
}
function s {
cat $FILE
}
function rs {
sort $FILE -o $FILE
}
function interactive {
echo "rad - Relationship Addition "
echo "\
Available Commands: a - add, c - add complex relationship,
s - show relationship, rs - resort relationship, h - help"
echo "Default file: ./db.pl"
while true
do
echo -n "rad> "; read cmd;
$cmd;
done
}
if [[ -z $* ]]
then
interactive
else
$*
fi
exit
Replies to rad 
Title |
Name |
Language |
When |
Re: rad |
NAT |
bash |
7 Years ago. |
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}