免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1420 | 回复: 8
打印 上一主题 下一主题

看看我写的脚本的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-05-30 14:05 |只看该作者 |倒序浏览

  1. #! /bin/ksh
  2. #scriptname:msg
  3. #一个dialog的练习
  4. #====================start====================#
  5. t="用户信息"
  6. name=$(print $LOGNAME)
  7. dialog --title $t --inputbox "注册名:" $zc 8 20
  8. if [[ $zc != $name ]]
  9. then
  10. dialog --title "警告" --msgbox "  用户$zc不存在!" 5 20
  11. else
  12. dialog --title $t --msgbox "用户$USER起始目录:\n$HOME\n登录信:\n$(w)" 10 100
  13. exit 0
  14. fi
  15. #====================over====================#
复制代码

问题:在这个脚本执行时,为什么不按我的要求去做?
注:在linux下.

论坛徽章:
0
2 [报告]
发表于 2003-05-30 15:11 |只看该作者

看看我写的脚本的问题

红袖姐姐帮我~~~~~~~

论坛徽章:
0
3 [报告]
发表于 2003-05-30 15:16 |只看该作者

看看我写的脚本的问题

[quote]原帖由 "991214"]红袖姐姐帮我~~~~~~~[/quote 发表:
   

没法帮你试,因为我的机器上没有 dialog  

论坛徽章:
0
4 [报告]
发表于 2003-05-30 15:19 |只看该作者

看看我写的脚本的问题

...

$zc 没有定义,它是什么?

论坛徽章:
0
5 [报告]
发表于 2003-05-30 15:28 |只看该作者

看看我写的脚本的问题

哦~~,真遗憾,实际dialog是个对话框,我就是想把我输入的信息在对话框中运行,因为在linux下很多安装程序都是这种对话框的形式,我也想尝试尝试,
$zc就是要接受的输入的变量.在dialog中就这样定义的(别的方法我都用过,不行的).
......
谢谢您红袖姐,我再自己个儿研究研究吧~~~

论坛徽章:
0
6 [报告]
发表于 2003-05-30 16:17 |只看该作者

看看我写的脚本的问题

man dialog
----------------
     --inputbox text height width [init]
              An  input  box  is  useful  when  you want to ask questions that
              require the user to input a string as the answer.   If  init  is
              supplied it is used to initialize the input string.  When enter-
              ing the string, the BACKSPACE key can be used to correct  typing
              errors.   If the input string is longer than can fit in the dia-
              log box, the input field will be scrolled.  On exit,  the  input
              string will be printed on stderr.

-------------------

  1. dialog --inputbox .....  2>/tmp/tmp$$
  2. input=`cat /tmp/tmp$$`
  3. echo "your input are $input"
复制代码

论坛徽章:
0
7 [报告]
发表于 2003-05-30 17:18 |只看该作者

看看我写的脚本的问题

谢谢~~
不过我的意思,是如何在脚本中判断dialog中输入的字符是否正确?
当输入的字符不是注册用户的时候,程序应该执行提示出错的那段信息,而现在,无论我输入什么字符他都提示用户不存在,??

论坛徽章:
0
8 [报告]
发表于 2003-05-30 18:33 |只看该作者

看看我写的脚本的问题

hello 991214,
查了一下帮助,好像用户的输入得借助临时文件,因为dialog把用户的输入送到stderr。

另,我没有ksh环境,我用sh写的,测试OK。

  1. #!/bin/sh
  2. dialog --title "用户信息" --inputbox "注册名" 8 20 2> temp.txt
  3. zc=`cat temp.txt`
  4. if [ $zc = "chinaunix" ];
  5. then
  6.         echo hello, $zc!
  7. else
  8.         echo you are a invalid user!
  9. fi
复制代码

论坛徽章:
0
9 [报告]
发表于 2003-05-30 19:51 |只看该作者

看看我写的脚本的问题

thanks for your help!
Pass ...
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP