【发布时间】:2014-10-16 23:09:04
【问题描述】:
我有这个代码:
#!/bin/bash
if [ $# -lt 2 ]; then
echo "usage: $0 <-lu> <string>"
exit 1
fi
while getopts "lu" OPT
do
case $OPT in
u) casechange=0;;
l) casechange=1;;
*) echo "usage: -u<upper> || -l<lower> <string>";
exit 1;;
esac
done
shift $(( $optind -1 ))
if [ $casechange -eq 0 ]; then
tr '[A-Z]' '[a-z]' <$string
elif [ $casechange -eq 1 ]; then
tr '[a-z]' '[A-Z]' <$string
else
echo "fatal error"
exit 1
fi
我收到两个错误:
line 15: shift -1: shift count out of rangeline 19: $string: ambiguous redirect
我做错了什么?我该如何解决这个问题?
【问题讨论】:
-
你在哪里定义
$string? -
显然没有。