Created
April 16, 2014 08:57
-
-
Save toshi0383/10836442 to your computer and use it in GitHub Desktop.
if文内で">"を使うと恐ろしいことが ref: http://qiita.com/toshi0383/items/b721b48fa780fe57e7c1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 間違い! | |
#!/bin/bash | |
n1=${1:?} | |
n2=${2:?} | |
n3=${3:?} | |
if [ $n1 > $n2 ];then | |
tmp=$n1 | |
n1=$n2 | |
n2=$tmp | |
fi | |
if [ $n2 > $n3 ];then | |
tmp=$n2 | |
n2=$n3 | |
n3=$tmp | |
fi | |
if [ $n1 > $n2 ];then | |
tmp=$n1 | |
n1=$n2 | |
n2=$tmp | |
fi | |
echo $n1 $n2 $n3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 正しい | |
#!/bin/bash | |
n1=${1:?} | |
n2=${2:?} | |
n3=${3:?} | |
if [ $n1 -gt $n2 ];then | |
tmp=$n1 | |
n1=$n2 | |
n2=$tmp | |
fi | |
if [ $n2 -gt $n3 ];then | |
tmp=$n2 | |
n2=$n3 | |
n3=$tmp | |
fi | |
if [ $n1 -gt $n2 ];then | |
tmp=$n1 | |
n1=$n2 | |
n2=$tmp | |
fi | |
echo $n1 $n2 $n3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment