原文:http://bash.cyberciti.biz/shell-math/swap-two-values-in-variables/
交换X和Y两个数的值,比如输入两个数,X为6,Y为12,运行结果,X为12,Y为6
以下是该shell脚本的源代码:
#!/bin/bash
# Shell Script to swap values in two variables x and y
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
echo "Enter value for x : "
read x
echo "Enter value for y : "
read y
echo "Before swap, x = $x and y = $y"
z=$x
x=$y
y=$z
echo "After swap, x = $x and y = $y" |