Linux大棚命令记录

  1. 查看系统支持的shell: cat  /etc/shells
  2. 查看当前系统用的shell: echo $SHELL
  3. 从bash切换到zsh: 先yum安装,然后 chsh -s /bin/zsh ,退出重新登录即可(chsh -s 实际上是修改了/etc/passwd文件)
  4.  env和export显示的环境变量
  5. set和declare显示的环境变量和自定义变量
  6. 指定PATH变量: export PATH=$PATH:/home/roc
  7. 有export则指定的是环境变量,没有export 的是指定自定义变量
  8. 在子进程中自定义变量无效的
  9. 从键盘输入自带提示语:
    1.  

      read -p "please input your name and place:"
      echo "welcome $REPLY"  $REPLY变量输出结果

    2. #!/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语句后面添加变量来接受输入

    3.  if read -s -p "please input your name and place:" name    # -s用来输入密码

    4. 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" #从文件读入

    5. #!/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了

    6. #!/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"    #使用重定向技术可以避免像上一个脚本在循环中又新建变量的问题

猜你喜欢

转载自www.cnblogs.com/Baronboy/p/9163925.html