- [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
语法报错还是生成了啊