【发布时间】:2013-11-20 16:39:13
【问题描述】:
我有一个脚本,我想禁止命令行中的一些命令(shutdown、rm、init)。但它似乎不起作用,因为它似乎匹配一切: 我怎么能这样做?
[root@devnull hunix]# cat p.sh
#!/bin/bash
string=$1;
if [[ "$string" =~ [*shut*|*rm*|*init*] ]]
then
echo "command not allowed!";
exit 1;
fi
[root@devnull hunix]# ./p.sh shutdown
command not allowed!
[root@devnull hunix]# ./p.sh sh
command not allowed!
[root@devnull hunix]# ./p.sh rm
command not allowed!
[root@devnull hunix]# ./p.sh r
command not allowed!
[root@devnull hunix]#
【问题讨论】:
标签: regex linux bash shell parameter-passing