zoukankan      html  css  js  c++  java
  • [Linux] Linux shell (1)

    *1 echo  $ var1=100      $ echo $var1       $ echo "hello world"
    hp@ubuntu:~$ fruit=apple
    hp@ubuntu:~$ echo "have ${fruit}(s)"
    have apple(s)
    hp@ubuntu:~$ echo -n "hello"     #忽略换行
    hellohp@ubuntu:~$
    hp@ubuntu:~$ echo -e "he\tllo"   #转移
    he llo
    *2 printf
    hp@ubuntu:~$ printf "%s %s %-5s %.2f\n" No name Mark 77.564
    No name Mark  77.56
    脚本语言通常不需要在使用变量之前声明其类型,只需要直接赋值就可以!在Bash中,每个变量都是字符串。
    *3 环境变量
    $ cat /proc/$PID/environ     # 查看某进程运行时的环境变量
    $ pgrep gedit     # 获得该进程的进程ID
    $ cat /proc/4067/environ | tr '\0' '\n'
    一些shell可用的常见的环境变量 HOME, PWD, USER, UID, SHELL
    *4 补充内容 
    hp@ubuntu:~$ echo ${#var1}    #字符串长度
    3
      算术运算 let, (()), [] 执行基本的算术操作。
      expr 和 bc 这两个工具也会非常有用。
    $ let result=no1+no2              $ let no1++            $ let no1--
    $ echo $result
    9
    result=$[ no1+no2 ]                  result=$[ $no1+5 ]                      result=$(( no1+50 ))
    expr同样可以用于基本算术运算 result='expr 3+4'                 result=$(expr $no1+5)
    echo "4 * 0.56" | bc
    2.24
    *5 文件描述符和重定向
    文件描述符是与文件输入,输出想关联的整数。它们用来跟踪已打开的文件。
    最常见的文件描述符  0-stdin, 1-stdout, 2-stderr
    $ echo "This is world" > temp.txt                         $ echo "This is world2" >> temp.txt
    $ cmd 2> stderr 1> stdout.txt
    /dev/null 是一个特殊的设备文件-黑洞。
    ........................
  • 相关阅读:
    Linux vi/vim
    Linux 磁盘管理
    Linux 用户和用户组管理
    Linux 文件与目录管理
    Linux 文件基本属性
    Linux 远程登录
    Linux 忘记密码解决方法
    Linux 系统目录结构
    Linux 系统启动过程
    linux -- su和sudo命令的区别
  • 原文地址:https://www.cnblogs.com/robbychan/p/3787159.html
Copyright © 2011-2022 走看看