一、脚本传参
1.三种方式
(1)第一种方式:直接传参
[root@localhost scripts]# cat tesh.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo "$1 第一种传参方式"
[root@localhost scripts]# sh tesh.sh zhx
zhx 第一种传参方式
[root@localhost scripts]# cat tesh.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo "$1 第一种传参方式"
ping -c1 -W1 $1
[root@localhost scripts]# sh tesh.sh www.baidu.com
www.baidu.com 第一种传参方式
PING www.a.shifen.com (220.181.38.150) 56(84) bytes of data.
64 bytes from 220.181.38.150 (220.181.38.150): icmp_seq=1 ttl=128 time=21.1 ms
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 21.122/21.122/21.122/0.000 ms
(2)第二种方式:赋值传参
[root@localhost scripts]# cat tesh.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
url=$1
name=$2
echo "name=$name"
ping -c1 -W1 $1
[root@localhost scripts]# sh tesh.sh www.baidu.com zhx
name=zhx
PING www.a.shifen.com (220.181.38.149) 56(84) bytes of data.
64 bytes from 220.181.38.149 (220.181.38.149): icmp_seq=1 ttl=128 time=16.4 ms
--- www.a.shifen.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 16.449/16.449/16.449/0.000 ms
(3)第三种方式:read读入
[root@localhost scripts]# read
hehe
[root@localhost scripts]# read test
hehe
[root@localhost scripts]# echo $test
hehe
[root@localhost scripts]# read -p "Please Input Name:" name
Please Input Name:zhx
[root@localhost scripts]# echo $name
zhx
[root@localhost scripts]# cat read.sh
#!/bin/bash
read -p "Please Input URL: " url
ping -c1 -W1 $url &>/dev/null
[ $? -eq 0 ] && echo "$url is ok" || echo "$url is error"
[root@localhost scripts]# sh read.sh
Please Input URL: www.baidu.com
www.baidu.com is ok
使用read方式修改主机名称或IP地址
[root@localhost scripts]# cat host.sh
#!/bin/bash
read -p "请输入主机名称: " name
hostnamectl set hostname $name
read -p "请输入新的IP地址: " ip
sed -i "s#200#$ip#g" /etc/sysconfig/network-scripts/ifcfg-eth0
hostname
grep $ip /etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost scripts]# sh host.sh
请输入主机名称: zhx
Unknown operation set
请输入新的IP地址: 201
localhost.localdomain
IPADDR=10.0.0.201
优化脚本
[root@localhost scripts]# cat host.sh
#!/bin/bash
network_dir=/etc/sysconfig/network-scripts/ifcfg-eth0
source_ip=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-eth0|awk -F. '{print $NF}'`
read -p "请输入主机名称: " name
hostnamectl set hostname $name
read -p "请输入新的IP地址: " ip
sed -i "s#$source_ip#$ip#g" $network_dir
hostname
grep $ip $network_dir
[root@localhost scripts]# sh host.sh
请输入主机名称: zhxin
Unknown operation set
请输入新的IP地址: 203
localhost.localdomain
IPADDR=10.0.0.203
2.核心变量
(1)
0
获取脚本的参数
(
2
)
0 获取脚本的参数 (2)
0获取脚本的参数(2)n 获取脚本的第n个参数
(3)KaTeX parse error: Expected 'EOF', got '#' at position 1: #̲ 获取脚本传参的总个数 (4…* 获取脚本的所有参数 不加双引号和
@
相同在循环中加上双引号则所有的参数视为一个参数
(
5
)
@ 相同 在循环中加上双引号则所有的参数视为一个参数 (5)
@相同在循环中加上双引号则所有的参数视为一个参数(5)@ 获取脚本的所有参数 不加双引号和
∗
相同在循环中加上双引号则所有的参数视为独立的参数
(
6
)
*相同 在循环中加上双引号则所有的参数视为独立的参数 (6)
∗相同在循环中加上双引号则所有的参数视为独立的参数(6)? 上一条命令的执行结果 0为成功 非0失败
(7)$$ 获取脚本的PID 脚本的PID 或进程的PID
(8)
!
获取上个在后台执行的脚本的
P
I
D
(
9
)
! 获取上个在后台执行的脚本的PID (9)
!获取上个在后台执行的脚本的PID(9)_ 获取脚本的最后一个参数 类似命令行中的esc .
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo "Hello World"
echo $1 $2 $3 $4 $5 $6 $7 $8 $9 ${10} ${11} ${12}
echo $#
[root@localhost scripts]# sh test.sh {a..z}
Hello World
a b c d e f g h i j k l
26
(3)$# 用来控制脚本传参的个数
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
[ $# -ne 2 ] && exit
echo $1 $2
[root@localhost scripts]# sh -x test.sh name
+ . /server/scripts/name.sh
++ name=zhx
+ '[' 1 -ne 2 ']'
+ exit
[root@localhost scripts]# sh -x test.sh name age
+ . /server/scripts/name.sh
++ name=zhx
+ '[' 2 -ne 2 ']'
+ echo name age
name age
(4)
∗
获取脚本的所有参数不加双引号和
* 获取脚本的所有参数 不加双引号和
∗获取脚本的所有参数不加双引号和@ 相同 在循环中加上双引号则所有的参数视为一个参数
加上双引号
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo $*
[root@localhost scripts]# sh test.sh zhx name age
zhx name age
[root@localhost scripts]# sh test.sh {a..z}
a b c d e f g h i j k l m n o p q r s t u v w x y z
(5) @ 获取脚本的所有参数不加双引号和 @ 获取脚本的所有参数 不加双引号和 @获取脚本的所有参数不加双引号和*相同 在循环中加上双引号则所有的参数视为独立的参数
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo "$*"
echo "$@"
[root@localhost scripts]# sh test.sh a b c z d
a b c z d
a b c z d
不加上引号
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
echo $*
echo $@
[root@localhost scripts]# sh test.sh zhx name age
zhx name age
zhx name age
[root@localhost scripts]# set -- 'z hui xin'
[root@localhost scripts]# set -- "z hui" xin
[root@localhost scripts]# echo $*
z hui xin
[root@localhost scripts]# echo $@
z hui xin
[root@localhost scripts]# echo "$*"
z hui xin
[root@localhost scripts]# echo "$@"
z hui xin
[root@localhost scripts]# for i in $*;do echo $i;done
z
hui
xin
[root@localhost scripts]# for i in $@;do echo $i;done
z
hui
xin
[root@localhost scripts]# for i in "$*";do echo $i;done
z hui xin
[root@localhost scripts]# for i in "$@";do echo $i;done
z hui
xin
(6)$? 判断上一条命令的执行结果 0为成功 非0失败
[root@localhost scripts]# ls
1.txt host.sh name.sh read.sh test.sh
[root@localhost scripts]# echo $?
0
[root@localhost scripts]# vim test.sh
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
touc test.txt
[root@localhost scripts]# sh test.sh
test.sh: line 9: touc: command not found
[root@localhost scripts]# echo $?
127
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
touc test.txt &>/dev/null
[ $? -eq 0 ] && echo "is ok" || echo "is error"
[root@localhost scripts]# sh test.sh
is error
[root@localhost scripts]# sh -x test.sh
+ . /server/scripts/name.sh
++ name=zhx
+ touc test.txt
+ '[' 127 -eq 0 ']'
+ echo 'is error'
is error
判断ping百度网通不通
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 www.baidu.com &>/dev/null
[ $? -eq 0 ] && echo "Ping is ok" || echo "Ping is error"
[root@localhost scripts]# sh test.sh
Ping is ok
[root@localhost scripts]# sh -x test.sh
+ . /server/scripts/name.sh
++ name=zhx
+ ping -c1 -W1 www.baidu.com
+ '[' 0 -eq 0 ']'
+ echo 'Ping is ok'
Ping is ok
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || echo "Ping $1 is error"
[root@localhost scripts]# sh test.sh www.baidu.com
Ping www.baidu.com is ok
[root@localhost scripts]# sh test.sh 10.0.0.1
Ping 10.0.0.1 is ok
[root@localhost scripts]# sh test.sh 127.0.0.1
Ping 127.0.0.1 is ok
[root@localhost scripts]# sh -x test.sh www.baidu.com
+ . /server/scripts/name.sh
++ name=zhx
+ ping -c1 -W1 www.baidu.com
+ '[' 0 -eq 0 ']'
+ echo 'Ping www.baidu.com is ok'
Ping www.baidu.com is ok
exit 返回的值我们可以自己定义 exit 后面可以跟0-255
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || exit 255
[root@localhost scripts]# sh test.sh www.baidu.com
Ping www.baidu.com is ok
[root@localhost scripts]# sh test.sh 10.0.0.4
[root@localhost scripts]# sh -x test.sh 10.0.0.4
+ . /server/scripts/name.sh
++ name=zhx
+ ping -c1 -W1 10.0.0.4
+ '[' 1 -eq 0 ']'
+ exit 255
(7)$$ 获取脚本的PID 脚本的PID 或进程的PID
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || exit 255
echo $$
[root@localhost scripts]# sh test.sh 127.0.0.1
Ping 127.0.0.1 is ok
23454
[root@localhost scripts]# ps axu |grep test.sh
root 23459 0.0 0.0 112808 976 pts/0 R+ 09:11 0:00 grep --color=auto test.sh
[root@localhost scripts]# ps axu |grep test.sh |grep -v grep
过滤进程pid
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || exit 255
echo $$
sleep 600
[root@localhost scripts]# sh test.sh 127.0.0.1
Ping 127.0.0.1 is ok
23503
[root@localhost ~]# ps axu |grep test.sh
root 23503 0.0 0.0 113284 1384 pts/0 S+ 09:16 0:00 sh test.sh 127.0.0.1
root 23511 0.0 0.0 112808 976 pts/1 R+ 09:17 0:00 grep --color=auto test.sh
[root@localhost ~]# ps axu |grep test.sh |grep -v grep
root 23503 0.0 0.0 113284 1384 pts/0 S+ 09:16 0:00 sh test.sh 127.0.0.1
过滤进程PID kill掉进程
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || exit 255
echo $$ &>/opt/test.txt
sleep 600
[root@localhost scripts]# sh test.sh 127.0.0.1
Ping 127.0.0.1 is ok
Killed
[root@localhost ~]# ps axu |grep test.sh
root 23532 0.0 0.0 113284 1388 pts/0 S+ 09:20 0:00 sh test.sh 127.0.0.1
root 23551 0.0 0.0 112808 976 pts/1 R+ 09:21 0:00 grep --color=auto test.sh
[root@localhost ~]# ps axu |grep test.sh |grep -v grep
root 23532 0.0 0.0 113284 1388 pts/0 S+ 09:20 0:00 sh test.sh 127.0.0.1
[root@localhost ~]# cat /opt/test.txt
23532
[root@localhost ~]# kill -9 `cat /opt/test.txt`
(8)$! 获取上个在后台执行的脚本的PID
[root@localhost scripts]# cat test.sh
#!/bin/bash
. /server/scripts/name.sh
#Author zhx
#Version V1.O
#QQ 1105816259
# print Hello world!
# 输出世界你好
ping -c1 -W1 $1 &>/dev/null
[ $? -eq 0 ] && echo "Ping $1 is ok" || exit 255
echo $$ &>/opt/test.txt
sleep 600
[root@localhost scripts]# sh test.sh 127.0.0.1 &
[3] 23617
[root@localhost scripts]# Ping 127.0.0.1 is ok
[root@localhost scripts]# echo $!
23617
[root@localhost ~]# cat /opt/test.txt
23617
[root@localhost scripts]# kill $!
[root@localhost scripts]# echo $!
23617
[3]+ Terminated sh test.sh 127.0.0.1
(9)$_ 获取脚本的最后一个参数 类似命令行中的esc .
[root@localhost scripts]# sh test.sh name age zhx
[root@localhost scripts]# echo $_
zhx
[root@localhost scripts]# sh test.sh name age zhuixin
[root@localhost scripts]# zhuixin -----这个是esc .
3.变量的字串
(1)变量的切割
awk 取值
[root@localhost scripts]# name="I am zhuixin"
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo $name|awk '{print $2}'
am
把mz取出来
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo $name |awk -F '[ah]' '{print $2}'
m z
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo ${name:2:2}
am
[root@localhost scripts]# echo ${name:3:3}
m
(2)变量的长度统计
统计长度第一种方法
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo $name |wc -L
12
统计长度第二种方法
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo ${#name}
13
统计长度第三种方法
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# expr length "$name"
13
统计长度第四种方法
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo $name |awk '{print length}'
12
统计长度第五种方法
[root@localhost scripts]# echo $name
I am zhuixin
[root@localhost scripts]# echo $name |awk '{print length ($0)}'
12
统计字符个数小于3的 输出到屏幕 第一种方法
[root@localhost scripts]# echo $name
I am zhuixin student I am 30
[root@localhost scripts]# echo $name |awk '{print length}'
28
[root@localhost scripts]# echo $name |xargs -n1
I
am
zhuixin
student
I
am
30
[root@localhost scripts]# echo $name |xargs -n1 |awk '{print length}'
1
2
7
7
1
2
2
[root@localhost scripts]# echo $name |xargs -n1 |awk '{if(length<3)print}'
I
am
I
am
30
统计字符个数小于3的 输出到屏幕 第二种方法
for 循环第一次
i=1 如果i<7 继续往后执行
if判断第一次
i
=
=
=
=
=
=
=
=
=
=
=
=
=
i =============
i=============i
$1 ========I
length 长度 ❤️
输出结果 第一次
$i$1
输出$1 内容 I
[root@localhost scripts]# echo $name
I am zhuixin student I am 30
[root@localhost scripts]# echo $name |awk '{print $NF}'
30
[root@localhost scripts]# echo $name |awk '{for(i=1;i<=NF;i++)if(length ($i) <3)print $i}'
I
am
I
am
30
统计字符个数小于3的 输出到屏幕 第三种方法
[root@localhost scripts]# cat for.sh
#!/bin/bash
for i in I am zhuixin student I am 30
do
echo $i
done
[root@localhost scripts]# sh for.sh
I
am
zhuixin
student
I
am
30
[root@localhost scripts]# cat for.sh
#!/bin/bash
for i in I am zhuixin student I am 30
do
echo ${#i}
done
[root@localhost scripts]# sh for.sh
1
2
7
7
1
2
2
使用for循环统计长度信息
[root@localhost scripts]# cat for.sh
#!/bin/bash
for i in I am zhuixin student I am 30
do
echo -e "${i}\t的长度是\t${#i}"
done
[root@localhost scripts]# sh for.sh
I 的长度是 1
am 的长度是 2
zhuixin 的长度是 7
student 的长度是 7
I 的长度是 1
am 的长度是 2
30 的长度是 2
用判断的方式统计长度小于3的 输出屏幕
[root@localhost scripts]# cat for.sh
#!/bin/bash
for i in I am zhuixin student I am 30
do
[ ${#i} -lt 3 ] && echo $i
done
[root@localhost scripts]# sh for.sh
I
am
I
am
30
(3)变量的删除
#号 是从前面往后删除
##号 是贪婪匹配 删除到最后
%号 是从后往前删除
%% 号贪婪匹配删除到最后
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo $url |awk -F www. '{print $2}'
baidu.com.cn
[root@localhost scripts]# echo ${url#*.}
baidu.com.cn
[root@localhost scripts]# echo ${url#*.*.}
com.cn
[root@localhost scripts]# echo ${url#*.*.*.}
cn
##号 贪婪匹配
[root@localhost scripts]# echo ${url##*.}
cn
% 号是从后往前删除
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo ${url%.*}
www.baidu.com
[root@localhost scripts]# echo ${url%.*.*}
www.baidu
%号的贪婪匹配 删除到最后
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo ${url%%.*}
www
%%号 贪婪匹配使用撬棍\进行转义
[root@localhost scripts]# test=9%
[root@localhost scripts]# echo $test
9%
[root@localhost scripts]# echo ${test%\%}
9
(4)变量的替换
第一种替换的方式 使用sed 替换
[root@localhost scripts]# echo $name
I am zhuixin student I am 30
[root@localhost scripts]# echo $name |sed 's#zhuixin#zhanghuixin#g'
I am zhanghuixin student I am 30
第二种替换的方式使用 变量的替换方法
[root@localhost scripts]# echo $name
I am zhuixin student I am 30
[root@localhost scripts]# echo ${name/zhuixin/zhanghuixin}
I am zhanghuixin student I am 30
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo ${url/baidu/sina}
www.sina.com.cn
/ 替换成一个
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo ${url/w/a}
aww.baidu.com.cn
// 贪婪匹配
[root@localhost scripts]# echo $url
www.baidu.com.cn
[root@localhost scripts]# echo ${url//w/a}
aaa.baidu.com.cn
4. 数值运算
1.整数运算
(1)expr + - * / % ^
[root@localhost scripts]# expr 1+1
1+1
[root@localhost scripts]# expr hehe
hehe
[root@localhost scripts]# expr 1 + 1
2
[root@localhost scripts]# expr 10 \* 10
100
[root@localhost scripts]# expr 10 - 5
5
[root@localhost scripts]# expr 10 / 5
2
[root@localhost scripts]# expr 10 % 3 -----取余数
1
(2)$ [ ]
[root@localhost scripts]# echo $[1+19]
20
[root@localhost scripts]# echo $[19-2]
17
[root@localhost scripts]# echo $[10/2]
5
[root@localhost scripts]# echo $[10 % 1]
0
[root@localhost scripts]# echo $[1+19]
20
[root@localhost scripts]# echo "1+19=$[1+19]"
1+19=20
[root@localhost scripts]# num1=10
[root@localhost scripts]# num2=20
[root@localhost scripts]# echo "$num1+$num2"
10+20
[root@localhost scripts]# echo "$num1+$num2=$[num1+num2]"
10+20=30
(3)$ (())
[root@localhost scripts]# echo $((1+10))
11
[root@localhost scripts]# echo $((11*19))
209
[root@localhost scripts]# echo $((10/2))
5
[root@localhost scripts]# echo $((20%20))
0
[root@localhost scripts]# echo $((10-4))
6
(4)let
开使echo $i 是没有的
[root@localhost ~]# echo $i
[root@localhost ~]# let i++
[root@localhost ~]# echo $i
1
[root@localhost ~]# let i=i+1
[root@localhost ~]# echo $i
2
[root@localhost ~]# let i=i+1
[root@localhost ~]# echo $i
3
let i++ ===========================i=i+1
[root@localhost ~]# echo $a
[root@localhost ~]# let ++a
[root@localhost ~]# echo $a
1
[root@localhost ~]# let ++a
[root@localhost ~]# echo $a
2
[root@localhost ~]# let a=++a
[root@localhost ~]# echo $a
3
不相同的是 在使用变量的时候
i++ 先赋值在运算
++i 先运算在赋值
unset 临时取消变量
[root@localhost ~]# unset i
[root@localhost ~]# echo $i
[root@localhost ~]#
2.小数运算
(1)bc
[root@localhost ~]# echo 1+1|bc
2
[root@localhost ~]# echo 1+1.5|bc
2.5
[root@localhost ~]# echo 1.3*1.5|bc
1.9
[root@localhost ~]# echo 1.3/1.5|bc
0
[root@localhost ~]# echo 1.5/1.5|bc
1
(2)awk
[root@localhost ~]# awk 'BEGIN{print 10+10}'
20
[root@localhost ~]# awk 'BEGIN{print 10^10}'
10000000000
[root@localhost ~]# awk 'BEGIN{print 10%10}'
0
[root@localhost ~]# awk 'BEGIN{print 10-10}'
0
[root@localhost ~]# awk 'BEGIN{print 10/10}'
1
[root@localhost ~]# awk 'BEGIN{print 10-10.5}'
-0.5
[root@localhost ~]# awk 'BEGIN{print 10-10.5.3}'
-0.50.3
[root@localhost ~]#echo 10 20|awk '{print $1+$2}'
30
(3)python
[root@localhost ~]# echo "print 10+10"|python
20
[root@localhost ~]# echo "print 10*10"|python
100
[root@localhost ~]# echo "print 10-10"|python
0