if [[ $1 != video* || audio* || pic* ]]
then
echo error
else
echo success
fi
case $1 in
video*|audio*|pic*) echo ok;;
*) echo error;;
esac
#!/bin/bash
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
if ! test_parameter "$1"; then
echo error
else
echo success
fi
exit 0
[guest@localhost sh]$ ./t.sh video
error
[guest@localhost sh]$ ./t.sh video*
success
[guest@localhost sh]$ ./t.sh audio
error
[guest@localhost sh]$ ./t.sh audio*
success
[guest@localhost sh]$ ./t.sh x
error
[guest@localhost sh]$
#!/bin/bash
error()
{
echo "error: $1" 1>&2
}
ok()
{
echo "success: $1" 1>&2
}
test_parameter()
{
echo "$1" | grep -q '\(video\|audio\|pic\)\*'
}
main()
{
if ! test_parameter "$1"; then
error "incorrect parameter: \"$1\""
else
ok "parameter is correct"
fi
}
main "$@" || exit 1
exit 0
[guest@localhost sh]$ ./t.sh
error: incorrect parameter: ""
[guest@localhost sh]$ ./t.sh video
error: incorrect parameter: "video"
[guest@localhost sh]$ ./t.sh video*
success: parameter is correct
[guest@localhost sh]$ ./t.sh audio
error: incorrect parameter: "audio"
[guest@localhost sh]$ ./t.sh audio*
success: parameter is correct
[guest@localhost sh]$ ./t.sh pic
error: incorrect parameter: "pic"
[guest@localhost sh]$ ./t.sh pic*
success: parameter is correct
[guest@localhost sh]$ ./t.sh x
error: incorrect parameter: "x"
[guest@localhost sh]$