当前时区 GMT+8, 现在时间是 2008-9-7 19:05 游客: 注册 登录 仅登录论坛 | 搜索 帮助


标题: 我自己写的代码段,有点小问题,高手帮忙看
kaitai502
新手上路
Rank: 1



UID 247001
精华 0
积分 19
帖子 38
阅读权限 10
注册 2008-2-21
状态 离线
发表于 2008-3-18 08:44  资料  短消息  加为好友 
我自己写的代码段,有点小问题,高手帮忙看

#<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
新手上路
Rank: 1



UID 247001
精华 0
积分 19
帖子 38
阅读权限 10
注册 2008-2-21
状态 离线
发表于 2008-3-18 08:46  资料  短消息  加为好友 
涉及到参数传递的问题,不妨详细说一下,谢谢!!

顶部
xpt
新手上路
Rank: 1



UID 248664
精华 0
积分 7
帖子 13
阅读权限 10
注册 2008-4-8
状态 离线
发表于 2008-4-9 08:45  资料  短消息  加为好友 


QUOTE:
原帖由 kaitai502 于 2008-3-18 08:44 发表
我想实现这样的功能: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
新手上路
Rank: 1



UID 247001
精华 0
积分 19
帖子 38
阅读权限 10
注册 2008-2-21
状态 离线
发表于 2008-4-18 17:09  资料  短消息  加为好友 
谢谢楼上的朋友!我试试!!

顶部
 


Powered by Discuz! 5.5.0  © 2001-2007 Comsenz Inc.
清除 Cookies - 联系我们 - 中国Linux公社 - WAP