欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

shell小结(15)

程序员文章站 2022-06-29 12:55:05
...
#!/bin/bash
if [ ! $# -eq 1 ];then
	echo "need only one param!"
	exit 1
fi

cat /etc/passwd | awk -F: '{print $1}' | grep -w $1

if [ $? -eq 1 ];then

su - << huawei  
userdel -rf $1  1>> ok.log 2>> fail.log
fi
-------------------------------------------------------------------------------------------
#!/bin/bash
read -p "enter your name?" name

read -p "enter your age?" age

echo "your name is ${name}, and your age is ${age}"


#!/bin/bash
sh re.sh << OVER
xuxu
35
OVER
-------------------------------------------------------------------------------------------
#!/bin/bash
while read k v
do
	#必须加上``
 eval  `echo "${k}=${v}"`
done < data.txt
echo 'name = '$name
-------------------------------------------------------------------------------------------
#!/bin/bash

cat /etc/hosts | grep -v '^#' | grep -v '^$' | while read line
do
	addr=`cat $line | awk '{print $1}'`
	ping -s -C1 $addr
done

-------------------------------------------------------------------------------------------
#!/bin/bash
while [ $# -gt 0 ]
do
	echo '$#='$#
	echo $1
	shift
done
-------------------------------------------------------------------------------------------
who -u:显示当前的所有用户,及这些用户的进程号
who -r:显示系统的运行级别
-------------------------------------------------------------------------------------------
sed '1a \
line1\
line2\
line3' data.txt
-------------------------------------------------------------------------------------------
sort -t: -k2 dd.txt

ls -A:显示所有文件,不包括.和..
-------------------------------------------------------------------------------------------
#!/bin/bash
if :#空命令,永远为真
then
   echo "ok"
else : #空命令,永远为真
fi

 

相关标签: Bash F#