shell_study

1. shell文件执行方式(两种)

sh test.sh #当test.sh没有可执行权限时,只能用这种方式
./test.sh #推荐用这个命令,sh有时会报错

没有可执行权限时,可用如下命令:

chmod u+x test.sh #给test.sh文件加可执行权限

ll #可查看文件有哪些权限

2. 判断目录是否存在

DATA=/home/liuwei/caffe #将路径保存在变量DATA中

test -d $DATA && echo 'exist' || echo 'not exist'  #用test -d命令判断该目录是否存在, test -f命令判断该文件是否存在

3.  if语句查看cpu或者mem信息

#!/bin/bash
#if语句查看cpu或者mem信息

echo 'Please input your hardware.'
read hd 

if [ $hd == cpu ];then
	echo 'Your cpu info is.'
	cat /proc/cpuinfo
elif [ $hd == mem ];then
	echo 'Your memory info is.'
	cat /proc/meminfo
else
	echo 'I dont know what you input.'
fi

猜你喜欢

转载自blog.csdn.net/infinita_LV/article/details/81123261