shell配置,选择,环境变量修改(ORACLE_HOME,ORACLE_SID),无法使用sqlplus

...

零,由于某种误操作,导致用户账户下的shell配置文件丢失被删除

一,你登录到对应主机后,默认使用的那种shell

$ echo $SHELL

$ pstree

$ pstree -up|grep sshd

二,bash,csh的全局配置,用户配置文件

三,配置对应的ORACLE_HOME,ORACLE_SID

export ORACLE_HOME=

export ORACLE_SID=

=====================================

四,参考资料:

 

http://www.ochef.net/2009/09/compare-unix-shell.html

随着在Unix和Linux平台下工作的时间越长,不同种类的shell繁多,感觉对shell的认识由清晰开始变得模糊,所以应该赶紧弄清楚它们,shell太重要了。以下内容来自互联网综合、整理后的。

.profile:是Bourne Shell (sh)的配置文件,Korn Shell (ksh)兼容sh所以也会使用.profile。

/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时该文件被执行,并从/etc/profile.d目录的配置文件中搜集shell的设置。

.bash_ profile:是bash特有的, 由于bash被设计成兼容sh、ksh并有csh的特征, 所以会在用户主目录依次查找.bash_profile, .bash_login,.profile并用找到的第一个作为自己的配置文件。

~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息。当用户登录时,该文件仅仅执行一次。默认情况下,它设置一些环境变量,执行用户的.bashrc文件。

.login 是C Shell (csh) 的配置文件。

在Linux下sh是bash的一个链接, 如果bash使用sh命令启动的, 就会以sh兼容方式运行使用.profile,可用man bash命令查看更详细的解释。

/etc/bashrc:为每一个运行bash shell的用户执行此文件,当bash shell被打开时,该文件被读取。

~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。

~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件。另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,它们是”父子”关系。

~/.bash_profile:是交互式、login 方式进入 bash 运行的;~/.bashrc 是交互式 non-login 方式进入 bash 运行的。通常二者设置大致相同,所以通常前者会调用后者。

-The End-

 

http://space.itpub.net/22666004/viewspace-618337

大家要尊重俺的劳动成果,转载请注明出处。本文首发自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    邮箱:zhaizhibin@hotmail.com

欢迎交换友情链接~~

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

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

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

 

--------------------------------------------------------------------------------

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

--------------------------------------------------------------------------------

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

oracle环境变量设置不正确或者PATH设置不正确。
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/shNote: The method for setting environment variables depends on which shell you are using.

THAT'S ALL.

########################

http://space.itpub.net/519536/viewspace-672034

故障处理】ORA-12162: TNS:net service name is incorrectly specified

本文将给大家阐述一个因未设置系统环境变量ORACLE_SID导致ORA-12162错误的案例。希望大家有所思考。

1.获得有关ORA-12162报错信息的通用表述信息
[oracle@asdlabdb01 ~]$ oerr ora 12162
12162, 00000, "TNS:net service name is incorrectly specified"
// *Cause:  The connect descriptor corresponding to the net service name in
// TNSNAMES.ORA or in the directory server (Oracle Internet Directory) is
// incorrectly specified.
// *Action: If using local naming make sure there are no syntax errors in
// the corresponding connect descriptor in the TNSNAMES.ORA file. If using
// directory naming check the information provided through the administration
// used for directory naming.

2.故障现象
本文所要描述的故障与这个通用的问题描述不同,在数据库服务器端使用TNSNAMES.ORA中记录的连接串连接没有问题,但如若未指定连接串,将会报出ORA-12162错误。

1)使用system用户尝试登录系统,此时便会收到报错如下信息
[oracle@asdlabdb01 ~]$ sqlplus system/sys

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:02 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:

2)使用sysdba身份登陆会得到同样的错误信息
[oracle@asdlabdb01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:54:48 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

ERROR:
ORA-12162: TNS:net service name is incorrectly specified

Enter user-name:

3)但此时,如果使用服务名方式连接数据库,是可以成功的,这也是该问题现象的诡异之处。
[oracle@asdlabdb01 ~]$ sqlplus system/sys@ora10g

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 22:53:41 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

system@ora10g>

想象一下,你的目标是快速的进入到数据库中进行维护操作,但此时登录都遭遇障碍,会感到非常的别扭。更让人抓狂的是,如果此时使用连接串登录到数据库进行停起操作,结果将会处于更加惨烈境况:数据库将因为无法正常登录导致无法启动数据库。

3.故障原因
诡异的故障背后的原因竟然是那样的基础:ORACLE_SID没有指定!
确认系统当前的ORACLE_HOME和ORACLE_SID环境变量
[oracle@asdlabdb01 ~]$ echo $ORACLE_HOME
/oracle/app/oracle/product/10.2.0/db_1
[oracle@asdlabdb01 ~]$ echo $ORACLE_SID

[oracle@asdlabdb01 ~]$

可见,此时只设置了ORACLE_HOME环境变量,但ORACLE_SID此时为空,这就是该问题的真实原因。

4.故障处理
给出ORACLE_SID,重新尝试登录。
[oracle@asdlabdb01 ~]$ export ORACLE_SID=ora10g
[oracle@asdlabdb01 ~]$ echo $ORACLE_SID
ora10g
[oracle@asdlabdb01 ~]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.3.0 - Production on Sat Aug 27 23:27:34 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

sys@ora10g>

OK,此时问题处理完毕。

5.小结
这个案例给我们的启迪是什么?
1)系统默认的错误提示信息有时不具有参考价值。而且,某些情况下这些错误提示还可能给我们带来误导。原因很简单,系统默认的错误提示信息不可能囊括所有故障现象;
2)任何系统级别的设置问题都有可能导致数据库系统出现异常;
3)在遇到故障的时候,我们需要沉着冷静。有些时候可能需要我们Check最原始的信息,切莫想当然。

建议:为了避免出现文章中提到的问题,第一,可以将ORACLE_SID等环境变量写入到系统profile中,但需要确保系统profile文件内容的有效性;第二,不在profile中进行填写,每次登录数据库服务器时手工完成数据库环境变量的指定,这种方法虽然增加了键盘的敲击,但它更直观、更有保障。

Good luck.

secooler
10.08.27

-- The End --

 

#############################

http://blog.csdn.net/cathysun118/article/details/4197778

 

Sql plus命令报command not found的解决笔记

1.问题描述
环境:linux9, Oracle10g.
在一台装有Oracle10g的Linux机器上,我运行sqlplus命令,报错"command not found",
运行别的命令(如:lsnrctl)也同样的错误。初步怀疑是路径问题,然后我尝试cd $oracle_home/bin下,
再次运行这些命令,还是同样的错误。但用ls能看到这些命令的存在。

2.分析和解决
这种情况应该是路径的问题,应该Oracle刚刚安装成功的,而且安装过程中没有出现异常。
我echo $oracle_home为空,echo $path也为空,问题就出在这里了。
然后我
export ORACLE_HOME=<your Oracle Home>
export PATH=$ORACLE_HOME/bin:$PATH
再次运行Sqlplus命令,ok,可以了。

最后,我用vi编辑 .profile文件,把
export ORACLE_HOME=<your Oracle Home>
export PATH=$ORACLE_HOME/bin:$PATH
加入.profile中。保存。
用source .profile启用该资源文件。

重新进入Linux系统,sqlplus命令一切正常。

 

 

 

#############################################

http://wiki.freebsdchina.org/howto/c/config_your_csh

 

选择 csh/tcsh

和许多刚从 Linux 转到 BSD 的人不同,我并没有装完 BSD 就顺手安装 bash
因为之前除了打命令,我没有用到额外的功能,bash 也好,csh 也罢,在我眼里都是当做 shell 来用。
但是渐渐地,我发现 csh 真的挺好用,它小巧、简单、开放,不需要额外依赖。

可能有人要拿脚本能力来作对比,比如bash脚本支持函数,csh不支持等。
对我来说,其实我从未像模像样地写过一个脚本,我的工作是 C++ 程序员。
从我的角度来看,
论脚本能力,其实bash、csh、zsh都比不上Python,
论兼容性,bashcsh、zsh都比不上sh,
论强大,bashcsh、zsh都比不上C/C++,甚至asm。
再看易学程度,bashcsh、zsh可能还是要输给Python。
综上,脚本能力忽略不计。:-x

好了,说了这么多大不敬的话,我们开始切入正题。8-)

配置文件

全局配置文件 /etc/csh.cshrc
个人配置文件 ~/.cshrc或~/.tcshrc

为了方便,建议修改全局性的配置文件,这样每个账号都可以享受便利。

按键绑定

通常,我们不设置按键绑定也能很好地工作,
但是对于远程登录,可能需要一些额外的配置。
比如,为了避免putty登录后,Home、End、Delete等变成~,你需要如下配置:

bindkey '\e[1~' beginning-of-line      # Home
bindkey '\e[3~' delete-char            # Delete
bindkey '\e[4~' end-of-line            # End
bindkey "^W" backward-delete-word      # Delete
bindkey -k up history-search-backward  # PageUp
bindkey -k down history-search-forward # PageDown

提示符

设置一个漂亮使用的的提示符可以让工作变得更愉快高效。
以下是一个合理的配置方案:

if ( $?prompt ) then                                #如果$prompt变量尚未设置,则做如下设置
     if ( "$uid" == "0" ) then                      #判断用户的uid
         set prompt = "%U%n%u@%m [%l] %B%~%b # "    #对于root,我们显示“#”号
     else
         set prompt = "%U%n%u@%m [%l] %B%~%b % "    #对于普通用户,显示“%”号。
     endif
endif

Konsole中的效果如下:
prompt2_img

一种彩色的配置方案如下:

set cr = "%{\e[31m%}" #开始红色
set cg = "%{\e[32m%}" #开始绿色
set c0 = "%{\e[0m%}"  #恢复为默认色彩

# Set some variables for interactive shells
if ( $?prompt ) then
    if ( "$uid" == "0" ) then
	set prompt = "%B%U%n%u@%m.$cr%l$c0%b %c2 %B%#%b " 
    else
	set prompt = "%B%U%n%u@%m.$cg%l$c0%b %c2 %B%%%b "
    endif
endif

Konsole中的效果如下:
prompt3.png

颜色代码:
1 for brighter colors
4 for underlined text
5 for flashing text
30 for black foreground
31 for red foreground
32 for green foreground
33 for yellow (or brown) foreground
34 for blue foreground
35 for purple foreground
36 for cyan foreground
37 for white (or gray) foreground
40 for black background
41 for red background
42 for green background
43 for yellow (or brown) background
44 for blue background
45 for purple background
46 for cyan background
47 for white (or gray) background

查看更多参数,及其作用:

man tcsh  #查看man手册
/%/       #搜索到“%/”开始的地方

环境变量等

你在抱怨 FreeBSD下的 ls 没有显示颜色, grep 出来的东西没有高亮吗? 那么你需要如下的配置:

#让 ls 鲜艳些
setenv LSCOLORS ExGxFxdxCxegedabagExEx
setenv CLICOLOR yes
#让 grep 匹配到的字符高亮
setenv GREP_OPTIONS --color=auto

对于在KDE下使用fcitx的人,需要如下三行设置
其实就是fcitx安装完后所提示的内容,如果你够细心的话。

setenv XMODIFIERS @im=fcitx
setenv QT_IM_MODULE xim
setenv GTK_IM_MODULE xim

嗯, ls 有颜色了,但是等等,为何 tab 不能补全?
你需要如下配置:

set autolist

如果命令输错了,让csh/tcsh 为你纠正:

set correct = cmd

为了在命令行启动某个游戏,或者kde程序,例如dolphin、kcalc,
你需要加两个路径到$path中去:
/usr/games /usr/local/kde4/bin/

set path = (/sbin /bin /usr/sbin /usr/local/bin /usr/games /usr/local/sbin /usr/bin $HOME/bin /usr/local/kde4/bin/) 

黑魔法防御术

 

重定向防御

重定向很强大,我们有时候会运行诸如“date » b.txt”,“ls -l > files.txt”等命令。
然而如果一不小心,把“»”输成“>”会造成什么后果呢?
为此,tcsh提供了noclobber这个选项:

set noclobber

有了它,悲剧就不会发生。如果“>”的目标文件已存在,tcsh会拒绝重定向。

覆盖防御

是否遇到过“mv a b”,从而把有用的b文件覆盖掉了?
为此,我们要让mv和cp的行为更谨慎:

alias mv 'mv -i'
alias cp 'cp -i'

如果目标文件已存在,mv和cp会拒绝操作,除非使用参数“-f”。

误删防御

rm这个命令自从诞生起,就一直是个危险的操作。
我们可以让rm更温和:

alias rm 'rm -i'

这样rm之前,会要求再次确认。

一切皆alias

前面,我们在黑魔法防御术中已经初步见识了alias。
alias不仅可以避免危险操作,还可以简化命令,自创命令。
除非极短,否则良好的alias命名,应当以某个统一的单词或字母开头,
例如下面即将展示的reload/edit系列、update系列、show系列等。

先展示最基本的alias,并逐条解释。

alias ..    'cd ..'       #两点即可回到上级目录
alias -	    'cd -'        #一杠返回上次的目录
alias q	    'exit'        #退出登录
alias rm    'rm -i'       #误删防御
alias del   'rm -r'       #删除整个目录
alias mv    'mv -i'       #覆盖防御
alias cp    'cp -i'       #覆盖防御
alias ls    'ls -I'       #root状态下,默认不显示隐藏文件(.*)。BSD的ls很特殊,root默认显示所有文件。
alias la    'ls -a'       #显示所有文件
alias ll    'ls -h -l'    #显示文件权限和大小(以合理的单位)
alias lr    'ls -R'       #递归显示目录
alias dh    'df -h -a -T' #以合适的单位显示所有磁盘的剩余空间,以及文件系统类型(如ufs、devfs、procfs)。
alias ds    'du -sh'      #以合适的单位显示查看每个文件/文件夹的大小

find/wc系列。快速查找当前目录下的所有c/cxx/python源码文件。结合wc可以统计行数。

alias find-c	'find . -name "*.h" -o -name "*.c"'
alias find-x	'find . -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cxx"'
alias find-py	'find . -name ".py"'
alias wc-c	'find . -name "*.h" -o -name "*.c" | xargs wc | sort -k 4'
alias wc-x	'find . -name "*.h" -o -name "*.hpp" -o -name "*.cpp" -o -name "*.cxx" | xargs wc | sort -k 4'
alias wc-py	'find . -name ".py" | xargs wc | sort -k 4'

reload/edit系列。实现快速修改,载入配置文件。

alias reload-rc.conf  'sh /etc/rc'
alias reload-cshrc    'unalias * && source /etc/csh.cshrc'
alias edit-xorg.conf  'vim /etc/xorg.conf'
alias edit-csh.cshrc  'vim /etc/csh.cshrc'
alias edit-make.conf  'vim /etc/make.conf'
alias edit-kern.conf  'vim /etc/kernconf/thinkpad'
alias edit-rc.conf    'vim /etc/rc.conf'
alias edit-vimrc      'vim /usr/local/share/vim/vimrc'

set系列。快速设置locale。

alias setlocale-zhcn 'setenv LC_ALL zh_CN.UTF-8 && setenv LANG zh_CN.UTF-8'
alias setlocale-c    'setenv LC_ALL C'

startx专用。
保持命令行下为英文locale(避免date等命令出现乱码),而让x环境为中文,适合手动startx而不是kdm的人。

alias sx 'setenv LC_ALL zh_CN.UTF-8 && setenv LANG zh_CN.UTF-8 && startx && setenv LC_ALL C'

make系列。快速编译kernel/world。

alias make-world  'cd /usr/src && make buildworld && cd -'
alias make-kernel 'cd /usr/src && make kernel KERNCONF=thinkpad && cd -'
alias make-installworld 'cd /usr/src && make installworld && make delete-old && cd -'

show系列。查看状态或某些信息。

alias show-ifstat	'systat -ifstat'    #查看网络接口的数据流量
alias show-geom		'gstat'             #查看I/O状态
alias show-thermal	'sysctl dev.acpi_ibm.0.thermal'  #查看ThinkPad笔记本的各部分温度
alias show-cpufreq	'sysctl dev.cpu.0.freq'          #查看当前cpu频率
alias show-cpulevels	'sysctl dev.cpu.0.freq_levels'   #查看可用的cpu频率
alias show-battery	'sysctl hw.acpi.battery.life && sysctl hw.acpi.battery.time' #查看电力
alias show-smartctl	'smartctl -a /dev/ad4'           #需要安装smartmontools,查看磁盘smart参数
alias show-alldep	'make all-depends-list'            #需要在ports的安装目录下执行,显示所有依赖
alias show-dep		'portmaster --show-work ./ | sort' #同上,且需要安装portmaster,只显示尚未安装的依赖
alias show-ver		'pkg_version -v'                   #查看是否有软件可更新

update系列。顾名思义,更新嘛。

alias update-locatedb    '/usr/libexec/locate.updatedb'            #更新locate数据库
alias update-kernsrc     'csup -L 2 /etc/supfiles/stable-supfile'  #同步kernel tree
alias update-ports       'portsnap fetch update'                   #同步ports tree
alias update-apps	 'portmaster -a --force-config'            #需要安装portmaster,更新所有软件,提示配置选项

杂项,均需要安装第三方软件才能用。

alias lt    'tree -N -C'       #需要安装tree。树状显示目录,-N可以保证中文显示,-C使用彩色
alias l3    'tree -N -C -L 3'  #目录最多递归三级
alias l4    'tree -N -C -L 4'  #四级
alias l5    'tree -N -C -L 5'  #五级
alias l6    'tree -N -C -L 6'  #六级
alias v	    'vim'              #不用说,我懒
alias m     'mocp'             #控制台下的cs架构播放器
alias getdir	'wget -c -r -np -k'                  #递归下载目录
alias ssh-home	'ssh raphael.vicp.cc -l root'        #用root账号登录,结合key可以免输密码
alias ftp-home   'ftp ftp://syh:syh@raphael.vicp.cc' #BSD自带的ftp,免输账号密码。主机已被电信和工信部和谐,勿再试
alias lft-phome	'lftp raphael.vicp.cc -u syh,syh'    #lftp的免输账号密码。
alias scons	'scons -Q -j 4'                      #构建工具,默认4个线程进行
alias valgrind-checkmem 'valgrind --tool=memcheck --leak-check=full'  #检查内存泄漏

最好的教材

最好的教材莫过于man手册,真的什么都有了。

man tcsh



##################


http://www.oschina.net/question/12_6576

一、选择一个好SHELL 

Unix 中常见的 shell 主要分为两大门派: 

sh: 

burne shell (sh)


burne again shell (bash)


        csh: 
c shell (csh)


tc shell (tcsh)
korn shell (ksh)


本人的教学环境是 FreeBSD6.1 + sh ,你也可以使用bash来学习,bash兼容sh。我尽量将所有的SHELL语句也在Redhat上面验证一下。 

FreeBSD上bash的安装方法有二: 
1、pkg_add -r bash


2、cd /usr/ports/shell/bash2 && make install clean


Linux 上默认的SHELL已经是bash了。 

查看自己机器上支持 Shell 种类的方法: 
# cat /etc/shells 


/bin/sh


/bin/csh
/bin/tcsh
/usr/local/bin/bash


设置自己的SHELL为sh 

# chsh
# vipw


使用chsh命令会打开一个编辑器(类似vi),需要修改其中的Shell: /bin/csh一项为Shell: /bin/sh 
使用vipw命令会打开一个编辑器(类似vi),需要修改指定用户所在行的最后一项为/bin/sh 

如果你是在FreeBSD上安装了 bash ,一般修改为 /usr/local/bin/bash 


二、SHELL基础(UNIX中的常用命令) 

[color=Red]列出目录中的内容[/color] 
ls 

[color=Red]FreeBSD需要使用使用-G参数,才能按文件类型显示为约定的颜色[/color] 
ls -G 

[color=Red]使用长格式,更出目录中的内容[/color] 
ls -l 

[color=Red]显示一个文本文件的内容[/color] 
cat  <文件名> 
cat -n /etc/passwd  (显示文件,并加行号) 
less  <文件名> 
more  <文件名> 

[color=Red]复制文件[/color]cp  <源文件名>   <目标文件名> 

[color=Red]文件更名或移动文件至其他目录[/color] 

mv  <文件名1>   <文件名2> 
mv  <目录1> <文件名>   <目录2> <文件名> 

[color=Red]显示当前工作的目录[/color] 
pwd  

[color=Red]建立目录(-p 建立多级目录)[/color] 
mkdir  <目录名> 
mkdir -p  <目录1> / <目录2> 

[color=Red]删除文件(或目录)[/color] 
rm  <文件名> 
rm -rf  <目录> 

[color=Red]显示时间和日期[/color] 
date 

[color=Red]显示N天前的时间和日期[/color] 

date -v -2d 

[color=Red]其他格式请自己试一下,或查看手册  man date[/color] 
date +%F 
date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S" 

[color=Red]显示字符串[/color] 
echo "hello c shell" 
printf "hello c shell\n" 

[color=Red]显示带颜色的字符串[/color] 
echo -e "\e[31mRed String\e[0m" 
printf  "\e[31mRed String\e[0m\n" 

具体的颜色代码,请参考: http://www.51sincere.com/2006-11/20061123123521.htm

 

原文链接: https://www.cnblogs.com/taosim/archive/2012/05/03/2480321.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    shell配置,选择,环境变量修改(ORACLE_HOME,ORACLE_SID),无法使用sqlplus

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/49366

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午1:00
下一篇 2023年2月9日 上午1:06

相关推荐