将多个命令的结果发送到一个文本文件?

发布于 2024-08-08 05:26:42 字数 633 浏览 5 评论 0原文

这就是我到目前为止所拥有的 - 我的保管箱公共 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一刻暧昧 2024-08-15 05:26:42

这是您想要实现的目标吗?

for PATH in `cat LIST`
   do
      echo $PATH
      dropbox puburl $PATH >> filename
   done

Is this what you are trying to achieve?

for PATH in `cat LIST`
   do
      echo $PATH
      dropbox puburl $PATH >> filename
   done
世界和平 2024-08-15 05:26:42

好的,我已经使用这里给我的建议来工作了:

for PATH in `cat LIST`
do
    echo $PATH
    dropbox puburl $PATH
done > PUBLIC-DIRECTORY-LIST

它创建了一个目录列表,并在它们下面创建了公共链接。现在是时候修剪目录以获得干净的链接文本文件了。

OK, I've got it working using the suggestions given to me here:

for PATH in `cat LIST`
do
    echo $PATH
    dropbox puburl $PATH
done > PUBLIC-DIRECTORY-LIST

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.

调妓 2024-08-15 05:26:42

=>创建文件并向第一行添加一些内容。 >>>附加到它的新行上。

echo txt=>PUBLIC-DIRECTORY-LIST.txt |
echo another text>>PUBLIC-DIRECTORY-LIST.txt 

The => creates the files and adds something to the first line. >> appends to it on a new line.

echo txt=>PUBLIC-DIRECTORY-LIST.txt |
echo another text>>PUBLIC-DIRECTORY-LIST.txt 
心作怪 2024-08-15 05:26:42

您应该使用带有输入重定向的 while read,而不是带有 cat filenamefor。另外,为了避免变量名称冲突,我将路径变量更改为小写,因为 shell 已经使用全大写字母。它不会影响您的交互式 shell,但可能会影响脚本中的某些内容。

另外,假设您希望输入文件中的行作为进度指示器显示在屏幕上,但不在输出文件中捕获,则此 echo 将其发送到 stderr

while read path
do
    echo $path >&2
    dropbox puburl $path
done < LIST > PUBLIC-DIRECTORY-LIST

You should use while read with input redirection instead of for with cat 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 to stderr.

while read path
do
    echo $path >&2
    dropbox puburl $path
done < LIST > PUBLIC-DIRECTORY-LIST
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文