Linux/Unix tr、变量、运算以及终端特性的设置等

使用tr的-s选项去除重复出现的字符:
[oracle@localhost tr.folder]$ cat oops.txt 
And the cowwwwwws went homeeeee
Or did theyyyyyyyyyyyyy
[oracle@localhost tr.folder]$ tr -s "[a-z]" < oops.txt 
And the cows went home
Or did they

删除空行:
[oracle@localhost tr.folder]$ cat oops.txt 
And the cowwwwwws went homeeeee




Or did theyyyyyyyyyyyyy




fas ods css
[oracle@localhost tr.folder]$ tr -s "[\012]" < oops.txt 
And the cowwwwwws went homeeeee
Or did theyyyyyyyyyyyyy
fas ods css

转换大小写:
[oracle@localhost tr.folder]$ echo "hello today is a Fine DAY" | tr "[a-z]" "[A-Z]"
HELLO TODAY IS A FINE DAY

删除数字:
[oracle@localhost tr.folder]$ cat oops.txt 
And the cowwwwwws went homeeeee
23
3123asadfas
123ffff

Or did theyyyyyyyyyyyyy

12


fas ods css
[oracle@localhost tr.folder]$ tr -cs "[a-z][A-Z]" "[\012*]" < oops.txt 
And
the
cowwwwwws
went
homeeeee
asadfas
ffff
Or
did
theyyyyyyyyyyyyy
fas
ods
css

[oracle@localhost etc]$ echo "`who | wc -l` users are on today"
2 users are on today

查看当前终端特性:
[oracle@localhost testDir]$ stty -a
speed 38400 baud; rows 44; columns 167; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke

设置styy xxx "xxx"

设置变量的默认值:
[oracle@localhost testDir]$ day=bad
[oracle@localhost testDir]$ echo "today is a ${day:-fine} day"
today is a bad day
[oracle@localhost testDir]$ unset day
[oracle@localhost testDir]$ echo "today is a ${day:-fine} day"
today is a fine day

设置只读变量:
[oracle@localhost testDir]$ readonly
declare -ar BASH_VERSINFO='([0]="3" [1]="1" [2]="17" [3]="1" [4]="release" [5]="i686-redhat-linux-gnu")'
declare -ir EUID="501"
declare -ir PPID="19022"
declare -r SHELLOPTS="braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor"
declare -ir UID="501"
[oracle@localhost testDir]$ weather=fine
[oracle@localhost testDir]$ readonly weather
[oracle@localhost testDir]$ echo ${weather}
fine
[oracle@localhost testDir]$ weather=fine2   
-bash: weather: readonly variable

设置环境变量:
[oracle@localhost testDir]$ console=tty1;export console
[oracle@localhost testDir]$ echo $console              
tty1

显示所有环境变量:
env

设置终端类型:
[oracle@localhost testDir]$ TERM=linux;export TERM
[oracle@localhost testDir]$ echo $TERM
linux

shell中的运算:
[oracle@localhost testDir]$ var=`date +%Y%m%d`
[oracle@localhost testDir]$ let "var2=$var+1" 
[oracle@localhost testDir]$ echo $var2        
20130304
[oracle@localhost testDir]$ echo $((var2=$var+3))
20130306
[oracle@localhost testDir]$ echo var2=$[$var+3]
var2=20130306
[oracle@localhost testDir]$ let "var++"
[oracle@localhost testDir]$ echo $var
20130304
[oracle@localhost testDir]$ echo $[var+1]
20130305

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值