Skip to content

Instantly share code, notes, and snippets.

@fooling
Last active October 13, 2015 09:28
Show Gist options
  • Save fooling/fdcc04978ee2846b7efd to your computer and use it in GitHub Desktop.
Save fooling/fdcc04978ee2846b7efd to your computer and use it in GitHub Desktop.
Shell
#!/bin/bash
#for loop in one line
for i in {1..10};do `nohup echo $i 0<&- &>>~/out.txt &` ;done
#!/bin/bash
#linux ubuntu
ps -aux | grep Wang | awk {'print $2'} | xargs kill
ps -aux | grep wine | awk {'print $2'} | xargs kill
#!/bin/bash
#这种方式可以把标准io当做文件输入到while循环中
#
while read line
do
echo "line is "${line}
done < /dev/stdin
#存在问题: 当while循环中有网络io的时候 , 会中断, 导致无法用.. 丑陋方式如下
#不过大规模文件会有问题
#update: 哦 因为输入缓冲本来应该由while消费的 , 但被其他命令给消费了, 所以得强制用 < /dev/null 给别人消费, 使while继续使用输入缓冲
n=0
while read line
do
echo "line is "${line}
array[$n]=${line}
n=$[$n+1]
done < /dev/stdin
for i in ${array[@]};
do
echo $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment