Chinaunix

标题: 看看我写的脚本的问题 [打印本页]

作者: 991214    时间: 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下.
作者: 991214    时间: 2003-05-30 15:11
标题: 看看我写的脚本的问题
红袖姐姐帮我~~~~~~~
作者: 红袖添香    时间: 2003-05-30 15:16
标题: 看看我写的脚本的问题
[quote]原帖由 "991214"]红袖姐姐帮我~~~~~~~[/quote 发表:
   

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


作者: 红袖添香    时间: 2003-05-30 15:19
标题: 看看我写的脚本的问题
...

$zc 没有定义,它是什么?
作者: 991214    时间: 2003-05-30 15:28
标题: 看看我写的脚本的问题
哦~~,真遗憾,实际dialog是个对话框,我就是想把我输入的信息在对话框中运行,因为在linux下很多安装程序都是这种对话框的形式,我也想尝试尝试,
$zc就是要接受的输入的变量.在dialog中就这样定义的(别的方法我都用过,不行的).
......
谢谢您红袖姐,我再自己个儿研究研究吧~~~
作者: kkng09    时间: 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"
复制代码

作者: 991214    时间: 2003-05-30 17:18
标题: 看看我写的脚本的问题
谢谢~~
不过我的意思,是如何在脚本中判断dialog中输入的字符是否正确?
当输入的字符不是注册用户的时候,程序应该执行提示出错的那段信息,而现在,无论我输入什么字符他都提示用户不存在,??
作者: deathcult    时间: 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
复制代码

作者: 991214    时间: 2003-05-30 19:51
标题: 看看我写的脚本的问题
thanks for your help!
Pass ...




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2