Basic command interpreter
parent
56175579de
commit
1bd9246f87
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Tests command interpreter
|
||||
#
|
||||
# Copyright (C) 2011 Mike Gerwitz
|
||||
#
|
||||
# This file is part of gsgp. 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 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
mypath=$( dirname $0 )
|
||||
. "$mypath/common"
|
||||
|
||||
# MSG command should output the given message (consuming all arguments) to
|
||||
# stdout
|
||||
msg="This is a test message"
|
||||
assert-equal "$( cmd MSG $msg )" "$msg" || {
|
||||
fail "Should properly output MSGs"
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Basic command interpreter
|
||||
#
|
||||
# Copyright (C) 2011 Mike Gerwitz
|
||||
#
|
||||
# This file is part of gsgp. 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 3 of
|
||||
# the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
##
|
||||
|
||||
# we accept the data as an argument list
|
||||
data="$@"
|
||||
|
||||
# the command will be the first word and the remaining text will act as the
|
||||
# argument list
|
||||
cmd=$( cut -d' ' -f1 <<< "$data" )
|
||||
args=$( cut -sd' ' -f2- <<< "$data" )
|
||||
|
||||
case "$cmd" in
|
||||
MSG)
|
||||
# the entire argument list represents the message
|
||||
echo "$args"
|
||||
;;
|
||||
esac
|
||||
|
Loading…
Reference in New Issue