这非常简单,但由于我仍然是shell脚本中的新生代,我无法做到这一点。很简单,我有一个菜单驱动的脚本,当用户输入他的选择时,我循环使用case函数并执行选定的菜单。 Uptil现在我正在用相同的脚本编写完整的代码。现在我将代码放在外部脚本的每个菜单选项中,并从那里访问代码。因此,它是这样的,从外部文件访问功能bash
#!/bin/bash
. course_func
file=names.dat
[ ! -f $file ] && > $file
while true
do
clear
echo ------------------------------------------
echo 1. Create a record
echo 2. View Records
echo 3. Search for records
echo 4. Delete records that match a pattern
echo ------------------------------------------
echo "Please enter your choice or enter (q) to quit: \c ";read choice
case $choice in
1)
create()
echo Enter to continue; read junk
;;
*)
clear
echo Wat nonsense enter properly
echo Enter to continue: ;read crap
;;
esac
done
然后,我创建,我写的创建()函数
代码是在链路另一外部脚本,
create()
{
while true
do
echo Please enter the name: ;read name
echo Please enter your surname: ;read surname
echo Please enter the address: ;read add
echo Please enter the cell no.: ;read cell
if yesno Do you really wish to save the following data to file
then
echo $name:$surname:$add:$cell >> $file
clear
echo The record has been inserted :D
else
echo The record was not save
fi
if yesno Do you wish to enter another record
then
:
else
xit
fi
done
}
addRecord()
{
}
search()
{
}
delRecord()
{
}
,但我得到一个错误,
course_func: line 31: syntax error near unexpected token `}'
course_func: line 31: `}'
menu_driven: line 18: syntax error near unexpected token `echo'
menu_driven: line 18: ` echo Enter to continue; read junk'
31行是我在哪里结束addRecord函数,它是空函数,f或其余案件。我们可以在bash中没有空的函数吗?
图片都没有,我们如何共享文本。 – 2012-04-10 18:50:38
对不起,有代码插入的问题,所以现在我添加的图像我终于发现我错了什么地方 – Sam007 2012-04-10 18:52:49
当你调用一个函数时不包括括号:'create' not'create()' – 2012-04-10 22:20:31