+ -
当前位置:首页 → 问答吧 → 如何用perl写个类shell

如何用perl写个类shell

时间:2011-02-14

来源:互联网

我想给程序加个壳,可以使用命令行的方式访问内部数据,最好输入命令时能和linux shell一样控制自如,哪位高手请指教...

作者: EDAlinux   发布时间: 2011-02-14

把perl脚本文件chmod一下,变成可执行,最好名字简单点,然后放到/usr/bin下面,就可以像用shell命令一样使用了,不知道你是不是这个意思。
我自己写得多文件查找就是这样用的
  1. $ fs
  2. usage: fs [-t filetype]/[-n num]/[-a] [string] [directory](opt)
  3. To find the string under the directory

  4.         -t filetype         Search the file in filetype
  5.         -n num                Print [num] items
  6.         -a                whole string match
  7.         -l num                the max level deepth of directory you want to search
  8.         -N num                select files which contain string of num or more times
  9.         -c                Match case
  10.         -i                display the line number
  11.         -f filename        find the file
  12. [string]        the string want to search
  13. [directory]        the directory to search, the default is the current one
复制代码

作者: 工藤*新一   发布时间: 2011-02-14

本帖最后由 paktc 于 2011-02-14 17:59 编辑

楼主是想借perl 自己打造一个命令行机制对吧。
然后可以自己设置命令,就像在shell中输入命令一样做perl的事情。

俺试了一下$command=<STDIN>;获取用户输入
然后正则表达式处理$command并作出相应操作。

不过<STDIN>的情况和 直接在shell输入信息的情况有些不同,
编辑一行命令时不能直接退格、左、右,
这些方向键会被转换成字符并显示在命令行上(我是不太习惯)

作者: paktc   发布时间: 2011-02-14