- Managing Running Processes
- Run a vi session with nice value 10
- # vim test&[1] 14771# renice +10 1477114771 (进程 ID) 旧优先级为 0, 新优先级为 10
- Open another session and list all the process given by your user by top command and sort them by nice value, find your vi process and process ID
- Open a new session first
- #top -o NI14771 root 30 10 149176 4700 2472 T 0.0 0.2 0:00.03 vim
- List all the processes with ps command, display your desired output fields and sort them by nice value, find your vi process and process ID
- #ps aux --sort -ni#ps aux --sort -ni|grep vim
- Writing Simple Shell Scripts
Write a script to print out all arguments given to your script, one per line, in the format like below. The number of parameters given to the script may be any number.
- #vim sh03.sh#!bin/bashread -p "How many number would you like to input?:" numfor((a=1; a<=$num; a++)); do read -p "please input nmuber$a:" num$adonefor((b=1; b<=$num; b++)); do echo -e "\$$b=$[num$b]"done
- Let's try
- # bash sh03.shHow many numbers would you like to input?:5please input nmuber1:12please input nmuber2:44please input nmuber3:22please input nmuber4:31please input nmuber5:45$1=12$2=44$3=22$4=31$5=45
PS.
When I use?./sh03.sh, it will display that
-bash: ./sh03.sh: bin/bash: 坏的解释器: 没有那个文件或目录
but it works when I use?bash sh03.sh?I don't know the reason.
尝试了培训过程中的一点疑问
*Flow control in shell - conditional execution
想尝试以下命令
[ test] && commands1||commands2
于是写了如下脚本
# vim sh04.sh#!bin/bashread -p "input a num:" numread -p "input anthor num:" num2[ "$num" -gt "$num2" ]&&echo -e "left"||echo -e "right"
尝试了一下脚本,
#bash sh04.shinput a num:4input anthor num:5right#bash sh04.shinput a num:5input anthor num:4left
想知道如果把 &&,|| 交换, 会怎么样, 所以把脚本改了一下
# vim sh05.sh#!bin/bashread -p "input a num:" numread -p "input anthor num:" num2[ "$num" -gt "$num2" ]||echo -e "left"&&echo -e "right"
尝试一下,
#bash sh05.shinput a num:4input anthor num:5leftright#bash sh05.shinput a num:5input anthor num:4left **right
看来是条件不成立就执行两个 commands, 成立就执行左边的.
还是没有弄明白这里的逻辑; 不成立的明白了, 当条件不成立的时候,|| 代表或,&& 是和, 所以一起执行后面两个命令; 但是按照我的理解, 如果条件成立, 应该像
[ test ] && commands
一样, 执行 && 后的命令, 但是事实上执行的是 && 之前的.
执行的是之后的, 我之前看错了
以上就是我的作业和一些想法.
来源: http://www.92to.com/bangong/2018/08-17/34035391.html