这很简单,但我不能让它工作.我想在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
Run Code Online (Sandbox Code Playgroud)
我已经尝试了一切,我不断收到此错误:
[~]# /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. )
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法,没有工作:
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]
Run Code Online (Sandbox Code Playgroud)
更改
if [$type == cpanel]
Run Code Online (Sandbox Code Playgroud)
至
if [ "$type" = "cpanel" ]
Run Code Online (Sandbox Code Playgroud)
和
LOGTYPES ="error, access"
Run Code Online (Sandbox Code Playgroud)
至
LOGTYPES="error, access"
Run Code Online (Sandbox Code Playgroud)
任何赋值必须在=(赋值运算符)周围没有空格.