我正在编写使用文件的shell脚本。我需要找到文件并为我打印一些重要的信息。多数民众赞成没问题......但是,我想添加一些“功能”,并使其与参数一起工作。其中一项功能是忽略一些与patterm匹配的文件(如* .c - 忽略所有c文件)。所以我设置了变量并添加了字符串。变量作为shell命令
#!/bin/sh
command="grep -Ev \"$2\"" # in 2nd argument is pattern, that will be ignored
echo "find $PWD -type f | $command | wc -l" # printing command
file_num=$(find $path -type f | $command | wc -l) # saving number of files
echo "Number of files: $file_num"
但是,命令以某种方式忽略我的变量并计算所有文件。但是,当我将相同的命令放入bash或shell时,我得到不同数量(正确的)文件。我虽然,它可能只是bash的,但在其他机器上,ksh在哪里,同样的问题和#!/bin/sh
到#!/bin/bash
也没有帮助。
参见[此FAQ](http://mywiki.wooledge.org/BashFAQ/050)。 –
reg的价值是什么? –
@AliissA有souhld是$命令,对不起... – Tehryn