如何在shell脚本中打印find命令的输出

时间:2018-04-12 20:05:49

标签: shell

shell脚本有两个参数:

  1. 要查找或搜索的文件的名称。
  2. 作为argument1提及的文件所在的目录名称。
  3. 我在通过脚本执行时遇到查找命令输出的问题,我试图运行在脚本运行中使用的相同命令,但在脚本内部我无法获得输出,请帮我纠正下面的代码。

    param_1=$1
    param_2=$2
    echo "First param: $1"
    echo "Second param: $2"
    ###list="$(find $param_2 -name $param_1 -type f)"
    temp_1="find  $2 -name "
    temp_2=" \"$1\""
    ###temp_3=" -type f"
    final_command=$temp_1$temp_2
    echo $final_command
    list=`$final_command`
    for file in $list; do if [ -f "$file" ]; then echo "Found: $file"; fi; done
    
    sh /home/xyz/find.sh one.txt /home/xyz/
    

0 个答案:

没有答案