这很简单,但我无法让它发挥作用。我想在ssh bash脚本中做一个简单的if else语句。这是我的代码:
#!/bin/sh
echo -n "enter what type of logs. (ie. cpanel, apache) "
read type
if [$type == cpanel]
then
LOGTYPES ="error, access"
else
LOGTYPES ="error, access, suphp, suexec"
fi
echo -n "enter which log to tail (ie. $LOGTYPES) "
read logs
echo -n "enter last number of lines to view. (ie. 10, 5000 etc) "
read lines
tail -$lines /usr/local/$type\/logs/$logs\_log
我已尝试过所有内容,但我一直收到此错误:
[~]# /apachetail
enter what type of logs. (ie. cpanel, apache) cpanel
/apachetail: line 5: [cpanel: command not found
/apachetail: line 9: LOGTYPES: command not found
enter which log to tail (ie. )
我尝试了以下方法,没有工作:
if [$type -eq cpanel]
if [$type -eq cpanel];
if [$type == cpanel];
if [$type = cpanel]
if [$type = cpanel];
if ["$type" = cpanel]
if ["$type" = cpanel];
if ["$type" == cpanel]
if ["$type" == cpanel];
if ["$type" -eq cpanel];
if ["$type" -eq cpanel]
答案 0 :(得分:9)
更改
if [$type == cpanel]
到
if [ "$type" = "cpanel" ]
和
LOGTYPES ="error, access"
到
LOGTYPES="error, access"
任何赋值必须在=(赋值运算符)周围没有空格。
答案 1 :(得分:3)
LOGTYPES =
应为LOGTYPES=
- 请注意缺少的空格。
[$type == cpanel]
应为[ $type == cpanel ]
- 请注意添加的空间。