Linux: 提示 Tips for shell programming

来源:互联网 发布:一点淘宝客服就登陆 编辑:程序博客网 时间:2024/05/04 11:26

Edit Time: 2006/12/06

By: JonsenElizee

E-mail: JonsenElizee@163.com

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

shell programming:
1: How to suppress the normal output when you grep
2: How to define a array and delete the first item using shift
3: How to subtring when awk
4: How to tr

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

#How to suppress the normal output when you grep

grep 'keyword' ./directory/fileName -q

#OUTCOME NULL

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

#How to subtring when awk

echo "Hello, World" | awk -F, '{print substr($1, 1, 3)}'

#OUTCOME Hel

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

#How to define a array and delete the first item using shift

cat > run.csh

#!/bin/csh

echo $1

shift

echo $1

set v = (a "value1" b "value2")

echo $v

shift v

echo $v

#TO RUN THE SHELL

/bin/csh run.csh param1 param2

#OUTCOME

param1

param2

a value1 b value2

value1 b value2

#COMEOUT

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

#How to tr

echo "hello" | tr 'a-z' 'A-Z'

#OUTCOME HELLO

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

#How to ps and kill

ps -ef | grep keyword

kill processId

 

 

原创粉丝点击