English 中文(简体)
BASH 脚本 - 命令输出字符串的安全限制
原标题:BASH Script - Safe limits for string from command output

日安! 日安! 日安! 日安!

我正在写一个相对简单的 BASH 脚本, 执行 SVN UP 命令, 捕捉控制台输出, 然后在文本上做一些邮件处理 。

例如:

#!/bin/bash
# A script to alter SVN logs a bit

# Update and get output
echo "Waiting for update command to complete..."
TEST_TEXT=$(svn up --set-depth infinity)
echo "Done"

# Count number of lines in output and report it
NUM_LINES=$(echo $TEST_TEXT | grep -c  .* )
echo "Number of lines in output log: $NUM_LINES"

# Print out only lines containing Makefile
echo $TEST_TEXT | grep Makefile

这和预期的一样有效(如上面的代码所评论的那样 ), 但我很担心如果我在非常大的仓库里运行它会发生什么。 是否对BASH 最大缓冲尺寸有限制, 用于保持控制台命令的输出?

我曾经寻找过类似的问题, 但与我正在寻找的东西没有什么相似之处。 我读过某些脚本在大型中间缓冲时需要使用 < code> alxags 。 我想知道这里在捕捉控制台输出时是否适用类似的东西 。

示例 :

# Might fail if we have a LOT of results
find -iname *.cpp | rm

# Shouldn t fail, regardless of number of results
find -iname *.cpp | xargs rm

谢谢

最佳回答

使用

var=$(hexdump /dev/urandom | tee out)

Bash没有抱怨; 我用略高于 1G 和 23. 5M 的线条杀死了它。 只要输出符合您的系统内存, 您就不必担心 。

问题回答

我看不出有什么理由不在这里使用临时文件。

tmp_file=$(mktemp XXXXX)

svn up --set-depth=infinity > $tmp_file
echo "Done"

# Count number of lines in output and report it
NUM_LINES=$(wc -l $tmp_file)
echo "Number of lines in output log: $NUM_LINES"

# Print out only lines containing Makefile
grep Makefile $tmp_file

rm $tmp_file




相关问题
Best practices for Subversion and Visual Studio projects

I ve recently started working on various C# projects in Visual Studio as part of a plan for a large scale system that will be used to replace our current system that s built from a cobbling-together ...

Changing username in SVN+SSH URI on the fly in working copy

I am using SVN+SSH to check out a working copy of repository from an SVN server on which all developers are members of a developer group and have full read/write permissions on the repository ...

ASP.NET MVC: How should it work with subversion?

So, I have an asp.net mvc app that is being worked on by multiple developers in differing capacities. This is our first time working on a mvc app and my first time working with .NET. Our app does not ...

How to search for file in subversion server?

Is there a way to search for a file in a subversion repository? Something similar to Unix find command, with which I can find the location of a file in a repository. I know there is svn list, but ...

热门标签