这是我的密码
my $shell_line_diff=`echo $(($(diff -U 0 ftest1.txt ftest2.txt|grep ^\+|wc -l)-$(diff -U 0 ftest1.txt ftest2.txt|grep ^\-|wc -l)))`;
print "difference in the number of lines is $shell_line_diff\n";
评估脚本在Linux上运行良好。
但在perl中,它给出了以下结果:
sh: -c: line 0: syntax error near unexpected token `
我试图递归遍历/home目录中的所有文件。我想对每个文件执行一些linux命令。因此,我使用for循环如下:
for i in /home/**/*
我也把下面的声明作为脚本的开始:
商店-s全球之星
shopt -s nullglob
但它被困在了循环中。这可能是处理这么多文件的问题。如果我将另一个目录(没有文件)分配给for循环,那么它将正确遍历。
我还能尝试什么。
完整守则:
#!/bin/bash
shopt -s globstar
shopt -s nullglob
echo "ggg"
for i in /home/**/*
do
NAME=${i}
我是linux的新手。我在linux中有一个包含大约250,000个文件的目录,我需要查找与某个模式匹配的文件数。
我尝试使用以下命令:
ls -1 20061101-20131101_kh5x7tte9n_2010_* | wc -l
我收到以下错误消息:
-bash: /bin/ls: Argument list too long
0
请帮帮忙。提前感谢
我正在尝试为android手机上的各种文件夹编写文件。
在一个完美的世界里,以下几点应该是可行的
adb shell ls -l | wc -l /sdcard/dcim/Camera
在我的脑海中,它应该输出./sdcard/dcim/摄像机的文件。
但它当然没有,相反,它说
The term 'wc' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was i
在我的程序中,我正在执行给定的命令并获得结果(日志和退出状态)。此外,我的程序还必须支持shell特定的命令(即包含shell特定字符~(tild)、|(管道)、*的命令)。但是当我尝试通过我的程序在我的主目录中运行sh -c ls | wc时,它失败了,它的退出状态是32512,同样在stderr流中,"sh: ls | wc: command not found"被打印出来。
但有趣的是,如果我在shell中运行命令sh -c ls | wc,它就能正常工作。
有什么问题吗?或者更可取的是,我如何通过我的程序运行外壳特定的命令(i.ec,我应该使用哪些参数运行哪个命令)?