LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 702|回复: 5

请教一个脚本问题?

[复制链接]
发表于 2003-8-8 18:08:38 | 显示全部楼层 |阅读模式
-----------------------------------
#!/bin/sh
if cp "$1" "#$1"
then
vi "$1"
else
echo "Failed to create backup copy"
fi
--------------------------------
请教:
这个脚本中 if cp "$1" "#$1"
"$1" 和 "#$1" 代表什么?
发表于 2003-8-8 18:22:41 | 显示全部楼层
$1是第一个位置参数,如:
urscript A
A即为第一个位置参数$1.
#$1,看你的脚本,是生成了一个A文件的备份文件"#A"
 楼主| 发表于 2003-8-8 18:29:25 | 显示全部楼层
对了,多谢。
 楼主| 发表于 2003-8-11 09:25:06 | 显示全部楼层
awk '{print ; if (NF != 0) print ""}' infile > outfile

在这行中,print; 代表输出什么?
if (NF!=0)是否指不是空行的行?
print"" 指的又是输出什么?


这些是从这里copy过来的。

For example, suppose I want to turn a document with single-spacing into a document with double-spacing. I could easily do that with the following Awk program:

   awk '{print ; print ""}' infile > outfile

Notice how single-quotes (' ') are used to allow using double-quotes (" ") within the Awk expression. This "hides" special characters from the shell you are using. You could also do this as follows:

   awk "{print ; print \"\"}" infile > outfile

-- but the single-quote method is simpler.

This program does what it supposed to, but it also doubles every blank line in the input file, which leaves a lot of empty space in the output. That's easy to fix, just tell Awk to print an extra blank line if the current line is not blank:

   awk '{print ; if (NF != 0) print ""}' infile > outfile
发表于 2003-8-11 11:21:15 | 显示全部楼层
第一个print; 等于 print $0; 打出当前行的内容
NF是当前行的记录数,print ""; 是打一个空行。

所以这个脚本是在不是空行的行后加一个空行,
我说的对吧
 楼主| 发表于 2003-8-11 11:39:19 | 显示全部楼层
明白了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表