bash学习笔记2-定制环境

 用户可以定制自己的shell环境 ,方便使用。

1、.bashrc文件

shell在启动前会去执行一些配置文件,.bashrc就是其中一个。这个文件放在~文件夹(即用户的home文件夹)下。可以修改这个.bashrc文件,这样在每次shell启动前就能执行一些命令。通常这些命令都是用来定制环境的,如设置shell变量,alias命令等。设置shell变量的语法为"name=value"或"export name=value",alias命令语法为"alias name=value",非常简单,但特别实用。

2、shell变量PS1和PS2

登陆shell后,每行开始都会显示一串字符串,可能是主机名或当前路径名称等等,一般称其为shell提示符。shell变量PS1就是用来设置shell提示符字符串的,只要修改PS1的指就可以替换shell提示符,如PS1="/w—> "将shell提示符改成当前路径名。其中,/w代表当前路径。下表列出了PS1使用的转义字符(from "Learning the bash shell"):
Command
Meaning
/a
The ASCII bell character (007)
/d
The date in "Weekday Month Day" format
/e
The ASCII escape character (033)
/H
The hostname
/h
The hostname up to the first "."
/n
A carriage return and line feed
/s
The name of the shell
/T
The current time in 12-hour HH:MM:SS format
/t
The current time in HH:MM:SS format
/@
The current time in 12-hour am/pm format
/u
The username of the current user
/v
The version of bash (e.g., 2.00)
/V
The release of bash; the version and patchlevel (e.g., 2.00.0)
/w
The current working directory
/W
The basename of the current working directory
/#
The command number of the current command
/!
The history number of the current command
/$
If the effective UID is 0 print a #, otherwise print a $
/nnn
Character code in octal
//
Print a backslash
/[
Begin a sequence of non-printing characters, such as terminal control sequences
/]
End a sequence of non-printing characters

在shell命令行中输入echo "aaa并按下enter时,由于引号没有配对,shell会跳入下一行,提示用户继续输入。此时shell提示符变成"> "了,这就是PS2的值。PS2也是shell变量,可以很容易被修改。例如执行PS2="< ",提示符将换成"> "。

3、其他SHELL变量

另外,经常接触的shell变量还有PATH、HOME和PWD

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值