QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2003|回复: 3

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

[复制链接]
发表于 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下!
可是我这样写,好像有点问题,自己不知道错在哪,请高手帮忙指点一下,谢谢!
 楼主| 发表于 2008-3-18 08:46:21 | 显示全部楼层
涉及到参数传递的问题,不妨详细说一下,谢谢!!
回复

使用道具 举报

发表于 2008-4-9 08:45:47 | 显示全部楼层
原帖由 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. :-)
回复

使用道具 举报

 楼主| 发表于 2008-4-18 17:09:37 | 显示全部楼层
谢谢楼上的朋友!我试试!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-4-19 23:35 , Processed in 0.090225 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表