sqlplus: Command not found. if: Expression Syntax. 错误解决方案 .

oracle登录时 sqlplus: Command not found. if: Expression Syntax. 错误解决方案

分类: ORACLE11g 650人阅读 评论(0) 收藏 举报

大家要尊重俺的劳动成果,转载请注明出处。本文首发自http://blog.csdn.net/erazy0/archive/2009/11/07/4782368.aspx

俺的百度空间http://hi.baidu.com/erazy0以及俺的ITPUB博客http://space.itpub.net/22666004/spacelist-blog也会同步更新

欢迎共同学习,交流,本人QQ:398467907    邮箱:[email protected]

欢迎交换友情链接~~

===================================华丽的分割线=========================================

 

      果然,事情永远不会一帆风顺,在连续出了N次故障后,今天,俺的 Oracle 11g 终于不甘寂寞,再次的出来“兴风作浪”了。

      今天的问题很简单,我登录进oracle用户以后,键入sqlplus出现如下错误:

 

 


 

[oracle@zzb ~]$ sqlplus
sqlplus: Command not found.


 

试了几次又重新启动都是这样的,于是立刻去百度,出来一大堆,具体有以下两种:

  1. oracle环境变量设置不正确或者PATH设置不正确。
  2. root登陆后应该 su - oracle,而不是直接 su oracle,中间加短线以继承oracle用户的环境变量。

第2种情况不用考虑,我是用secureCRT直接登录的oracle,不存在环境变量没继承的问题。

 

至于第1种情况我记得从没有改过家目录下的 .bash_profile 文件,我 vi  .bash_profile 看了一下没有发现有什么问题:

 


[oracle@zzb ~]$ vi .bash_profile

 

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

ORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_SID=zzb
PATH=$ORACLE_HOME/bin:$PATH

export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

stty erase ^h

#DISPLAY=192.168.0.1:0.0; export DISPLAY

LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH
".bash_profile" 28L, 464C written                            
[oracle@zzb ~]$ vi .bash_profile


# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

ORACLE_BASE=/u01
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_SID=zzb
PATH=$ORACLE_HOME/bin:$PATH

export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH

stty erase ^h

#DISPLAY=192.168.0.1:0.0; export DISPLAY

 


 

 

于是我又输入:

 


[oracle@zzb ~]$ env | grep ORA

[oracle@zzb ~]$


 

终于出问题了,oracle的环境变量竟然一个也没出来,难道是启动时出了什么问题?于是我又输入:

 


[oracle@zzb ~]$ source .bash_profile
if: Expression Syntax.


 

 

怪了,竟然出了语法问题。这时我突然想起来了,这几天我在学 Shell ,难道是我昨天切换到其他的 shell 下没有切换回来?似乎只有这样才会报语法问题吧,毕竟不同的 shell 之间语法还是有一些差异的。于是我就:

 

 


[oracle@zzb ~]$ echo $SHELL
/bin/csh

 

 

果然是 shell 的问题。于是我:

 


[oracle@zzb ~]$ exec bash
[oracle@zzb ~]$

[oracle@zzb ~]$ pstree
init─┬─acpid
     ├─anacron
     ├─atd
     ├─crond
     ├─cups-config-dae
     ├─cupsd
     ├─dbus-daemon-1
     ├─events/0
     ├─gpm
     ├─hald
     ├─htt───htt_server
     ├─khelper
     ├─khubd
     ├─kjournald
     ├─klogd
     ├─kseriod
     ├─ksoftirqd/0
     ├─kswapd0
     ├─kthread─┬─aio/0
     │         ├─ata/0
     │         ├─ata_aux
     │         ├─kacpid
     │         ├─kauditd
     │         ├─kblockd/0
     │         └─2*[pdflush]
     ├─migration/0
     ├─6*[mingetty]
     ├─24*[oracle]
     ├─portmap
     ├─rpc.idmapd
     ├─rpc.statd
     ├─scsi_eh_0
     ├─2*[sendmail]
     ├─sshd───sshd───sshd───bash───pstree
     ├─syslogd
     ├─udevd
     ├─vmhgfs
     ├─vmmemctl
     ├─vmware-guestd
     ├─xfs
     └─xinetd

[oracle@zzb ~]$ env|grep ORA
ORACLE_SID=zzb
ORACLE_BASE=/u01
ORACLE_HOME=/u01/oracle
[oracle@zzb ~]$

 


 

 

大家可以看到,现在一切正常了。然后再次输入:

 


[oracle@zzb ~]$ source .bash_profile
[oracle@zzb ~]$

 


 

 

这次没报错,然后我就:

 

 


 

[oracle@zzb ~]$ sqlplus /nolog

SQL*Plus: Release 11.1.0.6.0 - Production on Sat Nov 7 12:55:15 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

SQL> conn / as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started.

Total System Global Area  313860096 bytes
Fixed Size                  1299624 bytes
Variable Size             226495320 bytes
Database Buffers           79691776 bytes
Redo Buffers                6373376 bytes
Database mounted.
Database opened.
SQL> select * from dual;

D
-
X

 

 


 

可以看到,正常进入了。

最后,秉着好奇心,我又输入:

 

 


[oracle@zzb ~]$ echo $SHELL
/bin/csh


 

额。。。怎么还是 csh,pstree 里显示的明明只有 bash ,没办法,我只能:

 

 


[oracle@zzb ~]$ su -
Password:
[root@zzb ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
netdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bash
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
pegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologin
htt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
erazy0:x:500:500:erazy0:/home/erazy0:/bin/bash
oracle:x:501:501::/u01/oracle:/bin/csh  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<注意这行
[root@zzb ~]# vi /etc/passwd

root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
news:x:9:13:news:/etc/news:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
vcsa:x:69:69:virtual console memory owner:/dev:/sbin/nologin
rpm:x:37:37::/var/lib/rpm:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
netdump:x:34:34:Network Crash Dump user:/var/crash:/bin/bash
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
mailnull:x:47:47::/var/spool/mqueue:/sbin/nologin
smmsp:x:51:51::/var/spool/mqueue:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
pcap:x:77:77::/var/arpwatch:/sbin/nologin
apache:x:48:48:Apache:/var/www:/sbin/nologin
squid:x:23:23::/var/spool/squid:/sbin/nologin
webalizer:x:67:67:Webalizer:/var/www/usage:/sbin/nologin
xfs:x:43:43:X Font Server:/etc/X11/fs:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
gdm:x:42:42::/var/gdm:/sbin/nologin
pegasus:x:66:65:tog-pegasus OpenPegasus WBEM/CIM services:/var/lib/Pegasus:/sbin/nologin
htt:x:100:103:IIIMF Htt:/usr/lib/im:/sbin/nologin
named:x:25:25:Named:/var/named:/sbin/nologin
dovecot:x:97:97:dovecot:/usr/libexec/dovecot:/sbin/nologin
erazy0:x:500:500:erazy0:/home/erazy0:/bin/bash
oracle:x:501:501::/u01/oracle:/bin/bash
"/etc/passwd" 41L, 1932C written   


 

注意到被我加红的那一行,问题就出在这儿,看来是昨天练习 shell 的时候不小心把oracle用户的登陆shell给改了,现在我再:

 


 [oracle@zzb ~]$ echo $SHELL
/bin/bash

 


 

 

终于好了,至此,我的 sqlplus 不能登录的问题应该算是圆满解决了。

 

PostScripts:贴一段找来的Matlab error "if: Expression Syntax" in tcsh 作为参考

 

Solution:

The "if: Expression Syntax" error can occur if you have the SHELL environment variable set to something different than what is expected. For example, one MATLAB user reported this error and was able to trace it to their use of "tcsh" instead of "csh." Once they explicitly set the SHELL variable in .matlab6rc.sh to "csh" the "if: Expression Syntax" was resolved.

If you are using "csh" or "tcsh", the "if: Expression Syntax" error may also occur as a result of a syntax error in either the .cshrc or .tcshrc files. Please examine the appropriate file for any errors. Alternatively, you can have MATLAB use "sh" by entering the following before starting MATLAB:

setenv MATLAB_SHELL=/bin/sh

Note: The method for setting environment variables depends on which shell you are using.

 

你可能感兴趣的:(sqlplus)