如果我将cat命令保存到字符串中,然后执行它,那么我将得到一个错误。
linux# cmd="cat /data/test/test.tx* | grep toto"
linux# eval '$cmd'
cat: |: No such file or directory
cat: grep: No such file or directory
cat: toto: No such file or directory
即使是
linux# $cmd
cat: |: No such file or directory
cat: grep: No such file
我在Linux和solaris下运行相同的脚本。下面是脚本:
#!/bin/sh
index=0
ls /tmp | grep e |
while read fileWithE
do
echo $fileWithE
index=`expr $index + 1`
done
echo "index is $index"
由于while循环在子while中运行,所以在solaris和linux中,我期望'index is 0‘作为输出。但是在solaris中,$index是/tmp下包含'e‘的文件的实际数量。那么,虽然循环不会在solaris下的
我在Linux shell中有包含以下详细信息的文件
Sam , apple
jhon , banana
Sam , apple
jhon , banana
Sam , mango
jhon , banana
jhon , apple
Sam , apple
Sam , papaya
使用我的Linux命令,我可以得到如下结果
cat /names/fav.log | cut -d "," -f 1|sort |uniq -c | sort -rn
结果
Sam 5
jhon 4
但我需要第二列的uniq计数。如下所示
Required result
当按照通常的方式运行时,gdb会像预期的那样停止:
(gdb) break main
(gdb) run
Starting program ...
Breakpoint 1, main ...
在管道运行时,gdb从不停止:
(gdb) run | cat
Starting program: /home/sds/z | cat
...
During startup program exited normally.
(gdb)
如何调试管道时的程序行为?
我的设置:
$ gdb --version
GNU gdb (GDB) Amazon Linux (7.6.1-64.33.amzn1)
$
Perl程序使用IPC::Run通过在运行时确定的一系列命令将文件输送到另一个文件中,就像下面这个小测试节选所演示的:
#!/usr/bin/perl
use IO::File;
use IPC::Run qw(run);
open (my $in, 'test.txt');
my $out = IO::File->new_tmpfile;
my @args = ( [ split / /, shift ], "<", $in); # this code
while ($#ARGV >= 0) {
目前,我的任务是手动检查多个文件的内容。我在一个文本文件中列出了所有的文件,逐行(每一行末尾的换行符),目前我正在尝试编写一个bash脚本,它能够读取文本文件行,然后在nano中打开它们以供检查。当我在nano中打开它时会出现问题--我目前正在win10上作为一个子系统运行linux,所以我只有可用的终端。我现在的问题是,当我尝试这样做的时候:
Cat file | while read line; do nano “$line”; done
最小工作实例:
mkdir test
cd test
touch {a,v,c}
ls > file
Cat file | while rea