- 查看系统支持的shell: cat /etc/shells
- 查看当前系统用的shell: echo $SHELL
- 从bash切换到zsh: 先yum安装,然后 chsh -s /bin/zsh ,退出重新登录即可(chsh -s 实际上是修改了/etc/passwd文件)
- env和export显示的环境变量
- set和declare显示的环境变量和自定义变量
- 指定PATH变量: export PATH=$PATH:/home/roc
- 有export则指定的是环境变量,没有export 的是指定自定义变量
- 在子进程中自定义变量无效的
- 从键盘输入自带提示语:
-
read -p "please input your name and place:"
echo "welcome $REPLY" $REPLY变量输出结果 -
#!/bin/bash
if read -t 5 -p "please input your name and place:" name
then
echo "welcome $name"
else
echo "sorry,too slow"
fi
exit 0 #用-t设置超时时间,在read语句后面添加变量来接受输入 -
if read -s -p "please input your name and place:" name # -s用来输入密码
-
exec 3< c.txt
count=0
while read -u 3 var
do
let count=$count+1
echo "Line $count:$var"
done
echo "finished"
echo "Line no is $count" #从文件读入 -
#!/bin/bash
count=0
cat c.txt | while read line
do
echo "Line $count:$line"
let count=$count+1
done
echo "finiished"
echo "Line no is $count"
exit 0 #这种方法的结果是返回1 ,因为管道的两边一般需要新建进程,当执行完while后,新进程结束,当脚本执行结束后,输出的count是原来进程中的count,而不是while中的count了 -
#!/bin/bash
count=0
while read line
do
let count=count+1
echo "Line $count:$line"
done< c.txt
echo "finished"
echo "Line no is $count" #使用重定向技术可以避免像上一个脚本在循环中又新建变量的问题
-
Linux大棚命令记录
猜你喜欢
转载自www.cnblogs.com/Baronboy/p/9163925.html
今日推荐
周排行