11-17 rhel7 linux 学习课-6 实验

  • [root@ZZH ~]# vim 1-1.sh

#!bin/bash

pwd

ls -al

[root@ZZH ~]# bas

base64 basename bash bashbug bashbug-64

[root@ZZH ~]# bash 1-1.sh

/root

total 76

dr-xr-x---. 14 root root 4096 Nov 18 05:18 .

dr-xr-xr-x. 17 root root 265 Oct 24 08:11 ..

-rw-r--r--. 1 root root 22 Nov 18 05:18 1-1.sh

-rw-------. 1 root root 1702 Oct 24 07:20 anaconda-ks.cfg

-rw-------. 1 root root 1901 Nov 17 05:07 .bash_history

-rw-r--r--. 1 root root 18 Dec 29 2013 .bash_logout

-rw-r--r--. 1 root root 176 Dec 29 2013 .bash_profile

-rw-r--r--. 1 root root 176 Dec 29 2013 .bashrc

drwx------. 16 root root 4096 Oct 27 06:05 .cache

。。。

 

  • [root@ZZH ~]# vim 1-2.sh

#!/bin/bash

echo "name $0"

echo "total $#, $*"

echo "first $1,fifth $5"

n[root@ZZH ~]# bash 1-2.sh a b c d e f g

name 1-2.sh

total 7, a b c d e f g

first a,fifth e

 

  • [root@ZZH ~]# [ -d /etc/fstab]

bash: [: missing `]'

[root@ZZH ~]# [ -d /etc/fstab ]

[root@ZZH ~]# echo $?

1

 

  • [root@ZZH ~]# [ $USER = user ] || echo "root"

root

 

  • [root@ZZH ~]# FM=`free -m | grep Mem: | awk '{print $4}'`

[root@ZZH ~]# [ $FM -lt 1024 ] && echo "insuff mem"

insuff mem

 

  • [root@ZZH ~]# vim 1-3.sh

[root@ZZH ~]# cat 1-3.sh

#!/bin/bash

ping -c 3 -i 0.2 -w 2 $1 &> /dev/null

if [$? -eq 0] 空格忘记加

then

echo "Host $1 is OL"

else

echo "Host $1 is ofL"

fi

[root@ZZH ~]# bash 1-3.sh 127.0.0.1

1-3.sh: line 3: [0: command not found

Host 127.0.0.1 is ofL

[root@ZZH ~]# vim 1-3.sh

[root@ZZH ~]# bash 1-3.sh 127.0.0.1

Host 127.0.0.1 is OL

[root@ZZH ~]#

 

  • [root@ZZH ~]# vim users.txt

[root@ZZH ~]# cat users.txt

shouji

pinggup

shuben

diannao

xxgx

mml

[root@ZZH ~]# bash 1-4.sh

ENT PW:xxxxxxxx

1-4.sh: line 14: ehco: command not found

1-4.sh: line 14: ehco: command not found

1-4.sh: line 14: ehco: command not found

1-4.sh: line 14: ehco: command not found

1-4.sh: line 14: ehco: command not found

1-4.sh: line 14: ehco: command not found

[root@ZZH ~]# cat 1-4.sh

#!/bin/bash

read -p "ENT PW:" PASSWD

for UNAME in `cat users.txt`

do

id $UNAME &> /dev/null

if [ $? -eq 0 ]

then

echo "exists"

else

useradd $UNAME &> /dev/null

echo "$PASSWD" | passwd --stdin $UNAME &> /dev/null

if [ $? -eq 0 ]

then

ehco "$UNAME , CREATE" # echo~~~~~

else

echo "$UNAME , FAILURE"

fi

fi

done

修改后

[root@ZZH ~]# bash 1-4.sh

ENT PW:xxxxxx

exists

exists

exists

exists

exists

exists

语法报错还是生成了啊

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值