kaitai502 发表于 2008-3-18 08:44:50

我自己写的代码段,有点小问题,高手帮忙看

#<bash>
echo -n "请输入所要查询文件的路径:";read mtv

mtv="$1"
echo "The program is \"`basename $0`\"."
if [ -d $mtv ]
then
read
fmtv()
{
until [ -e "$1" ] #测试"$1"的文件是否存在
do
a=`find $mtv -name $1`
if [ -f $a ]
then
   cp$a$HOME/lmtv
fi
echo "$a复制完成!"
cat $1
shift #参数左移
done
}
else
echo "路径名称错误!"

我想实现这样的功能:1)判断是否是正确的目录
2)输入文件名,查找并复制到指定的目录lmtv下!
可是我这样写,好像有点问题,自己不知道错在哪,请高手帮忙指点一下,谢谢!

kaitai502 发表于 2008-3-18 08:46:21

涉及到参数传递的问题,不妨详细说一下,谢谢!!

xpt 发表于 2008-4-9 08:45:47

原帖由 kaitai502 于 2008-3-18 08:44 发表 http://www.linuxfans.org/bbs/images/common/back.gif
我想实现这样的功能:1)判断是否是正确的目录
2)输入文件名,查找并复制到指定的目录lmtv下!
可是我这样写,好像有点问题 ...

- remove the line mtv="$1", it overwrite what you've just read
- define the function at the top of the script, instead of in the middle the script
- keep in mind that find might return many files!

Most importantly.

try it out on command line before put everything in a big script -- go step by step. :-)

kaitai502 发表于 2008-4-18 17:09:37

谢谢楼上的朋友!我试试!!
页: [1]
查看完整版本: 我自己写的代码段,有点小问题,高手帮忙看