Shell自动交互的三种方法


方法一


(echo "password";) | read input_pwd

方法二


read input_pwd << EOF

password

EOF

方法三


#!/usr/bin/expect

spawn ssh root@192.168.0.1

expect "password:"

send "123\n"

interact

Advertisements

有趣的Shell字符串


 

#!/usr/bin/env bash
str=$1
if [[ "$str" = "" ]]; then
     echo "1 empty"
fi

if [[ "$str" = " " ]]; then
    echo "2 empty"
fi

if [[ "$str" = "0" ]]; then
    echo "3 empty"
fi

if [[ "$str" = "00" ]]; then
    echo "4 empty"
fi

if [[ "$str" -eq 0 ]]; then
    echo "5 empty"
fi

if [[ "$str" -eq 000 ]]; then
    echo "6 empty"
fi

if [[ "$str" -eq '0' ]]; then
    echo "7 empty"
fi

if [[ "$str" -eq '00' ]]; then
    echo "8 empty"
fi
## show results
1 empty
5 empty
6 empty
7 empty
8 empty