|
一:输出命令如下
1.echo
-e 解析转义
\c不换行
\t 跳格
\n换行
#echo "welcome,what is your name:\c"
#echo -n "welcome,what is your name:"
编辑一个echo.sh来解释
#vi echo.sh
#!/bin/bash
echo -e "enter you name:\c"
read name //read读取键盘给出的变量,赋值给name
echo"$name"
echo -n "welcome book"
echo -e "welcome b\took"
echo -e "welcome book\n"
echo "abc"
#chmod +x echo.sh
#./echo.sh
2.read
编辑一个脚本解释read
#vi read.sh
#!/bin/bash
echo -e "your first name:\c"
read first
echo -e "your middle name:\c"
read middle
echo -e "your last name:\c"
read last
echo -e "你输入的三个名字是:"
echo "$first"
echo "$middle"
echo "$last"
#chmod +x read.sh
#./read.sh
3,管道 | 取当前Ip
#ifconfig | grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'| awk -F ';' '{print $2}'
grep "inet addr" //取有inet addr 的那行
grep -v "127.0.0.1" //过滤掉包含127.0.0.1的那行
awk '{print $2}'
// awk默认以空格为分隔符,取该行第二部分,就是第一个空格后,第二个空格前部分
awk -F ':' '{print $2}'
//-F 指定awk以:为分隔符,取第一个冒号后,第二个冒号前部分!!!
3.1
#ip=`ifconfig | grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'| awk -F ';' '{print $2}'`
#echo $ip
3.2
#vi ip.sh
#!/bin/bash
ip=`ifconfig | grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'| awk -F ';' '{print $2}'`
echo "$ip"
3.3
#vi ip.sh
#!/bin/bash
ip=$(ifconfig | grep "inet addr"| grep -v "127.0.0.1"|awk '{print $2}'| awk -F ';' '{print $2}')
echo "$ip"
|
|
|