[Linux] Linux shell (1)
来源:互联网 发布:逆战领枪软件 编辑:程序博客网 时间:2024/06/05 20:45
*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 是一个特殊的设备文件-黑洞。
........................
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] Linux shell (1)
- linux shell 学习1
- linux shell $1问题
- LINUX SHELL复习1
- linux ---- shell ---- 1
- Linux---shell(1)
- linux shell脚本-1
- Linux-shell基础-1
- linux shell解析1
- Linux shell(1)
- linux shell(1)
- linux shell(1)
- linux shell demos(1)
- linux shell:[1] ()、(())、[]、[[]]、{}使用方法
- Linux Shell
- Linux Shell
- Linux Shell
- Linux Shell
- MFC OCX 控件事件的添加和处理
- 一个构造和析构函数很经典的例子(继承相关)
- derby获得查询结果条目数
- Options Menu的使用
- Android中延时函数
- [Linux] Linux shell (1)
- SBC (session border controller)
- 字符串太长转换为分段显示
- Android系统框架和几种调用流程 .
- UVA 694 - The Collatz Sequence
- Software Craftsmanship - code kata
- 别让你的敏感词过滤系统把正常的文字过滤了!
- 细节处体现对用户的尊重
- MonoDevelop几个常用的快捷键