将多个命令的结果发送到一个文本文件?
这就是我到目前为止所拥有的 - 我的保管箱公共 URL 用于公共 URL 目录的创建脚本(getdropbox.com - 我认为是 gpl)。我的 LIST
文件是使用 ls 按以下方式创建的:
ls -d ~/Dropbox/Public/PUBLICFILES/* > LIST
dropboxpuburl.sh:
for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH > ~/URLLIST/$PATH
done
现在这将创建一系列文件 - 每个文件中都包含 dropbox puburl。
问题是:如何使该脚本将所有公共链接重定向到一个文本文件中,每个文件占一个新行 - 名称可能为 PUBLIC-DIRECTORY-LIST?
This is what I have so far - my dropbox public URL creation script for a directory of public URLs (getdropbox.com - gpl I think). My LIST
file was created using ls in the following fashion:
ls -d ~/Dropbox/Public/PUBLICFILES/* > LIST
dropboxpuburl.sh:
for PATH in `cat LIST`
do
echo $PATH
dropbox puburl $PATH > ~/URLLIST/$PATH
done
Now this creates a whole series of files - each with the dropbox puburl in them.
The question is: How can I cause this script to redirect all the public links into one text file, each on a new line - perhaps with the name PUBLIC-DIRECTORY-LIST?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是您想要实现的目标吗?
Is this what you are trying to achieve?
好的,我已经使用这里给我的建议来工作了:
它创建了一个目录列表,并在它们下面创建了公共链接。现在是时候修剪目录以获得干净的链接文本文件了。
OK, I've got it working using the suggestions given to me here:
It creates a list of the directories, and below them the public link. Now it is time to prune the directories for a clean text file of links.
=>创建文件并向第一行添加一些内容。 >>>附加到它的新行上。
The => creates the files and adds something to the first line. >> appends to it on a new line.
您应该使用带有输入重定向的
while read
,而不是带有cat filename
的for
。另外,为了避免变量名称冲突,我将路径变量更改为小写,因为 shell 已经使用全大写字母。它不会影响您的交互式 shell,但可能会影响脚本中的某些内容。另外,假设您希望输入文件中的行作为进度指示器显示在屏幕上,但不在输出文件中捕获,则此
echo
将其发送到stderr
。You should use
while read
with input redirection instead offor
withcat filename
. Also, in order to avoid variable name conflicts I changed your path variable to lowercase since the shell uses the all-caps one already. It won't affect your interactive shell, but it could affect something in your script.Also, assuming that you want the lines from your input file to be displayed to the screen as a progress indicator, but not captured in your output file, this
echo
sends it tostderr
.