Chinaunix首页 | 论坛 | 博客
  • 博客访问: 210440
  • 博文数量: 76
  • 博客积分: 2231
  • 博客等级: 大尉
  • 技术积分: 826
  • 用 户 组: 普通用户
  • 注册时间: 2011-10-27 09:15
文章分类

全部博文(76)

文章存档

2011年(76)

ada

分类: LINUX

2011-11-26 09:01:10

创建一个有内容的文件
    cat >> /tmp/aa.txt << "EOF"
    > hello word
    > EOF
    
cat  >> a.txt <>hello,world
>EOF

谁说 echo 只能单行?
echo '1
2
3' > filename

bash-3.2$ echo '1
> 2
> 3' > aaa
bash-3.2$ cat aaa
1
2
3

不过csh的echo多行是不行的:
leitz@labrnc172[33]> echo $0
csh
leitz@labrnc172[34]> echo '1
Unmatched '.
leitz@labrnc172[35]> 2
2: Permission denied.
leitz@labrnc172[36]> 3' > filename
Unmatched '.

由于我的脚本里还有!#等符号,所以用echo出问题了,还是用cat比较好。错误如下:
bash-3.2$ echo ‘#! /opt/swe/bin/expect
‘#! /opt/swe/bin/expect
bash-3.2$ spawn su leitz
bash: spawn: command not found
bash-3.2$ expect "Password: "
execution expect-5.39/expect (asb_shanghai/rncenv/linux)
couldn't read file "Password: ": no such file or directory
bash-3.2$ send "asb*1234\r"
bash: send: command not found
bash-3.2$ expect eof
execution expect-5.39/expect (asb_shanghai/rncenv/linux)
couldn't read file "eof": no such file or directory
bash-3.2$ exit’ > test.txt
bash: exit’: command not found


csh也可以,就是比较麻烦

echo '1\
2\
3' > filename

看来 csh 还真的是用 cat <

 # cat <> af
> fasd
> af
> EOF
af
fasd
af

shell乘法
$ a=$((2*60))
$ echo $a
120

$ a=`expr 10 \* 3`
$ echo $a
30

取匹配行的行号
dmidecode | awk '/Handle 0x0001/{print NR}'
dmidecode | sed  -n '/Handle 0x0001/='
dmidecode | grep  -n "Handle 0x0001" | awk -F ":" '{print $1}'

dmidecode | awk -vRS="" '/Handle 0x0001/'
阅读(2158) | 评论(0) | 转发(0) |
0

上一篇:asfa

下一篇:数组

给主人留下些什么吧!~~