将脚本作为输入,执行并测试错误

时间:2015-11-29 23:33:07

标签: bash scripting

我正在尝试创建一个脚本,该脚本采用脚本的名称,执行所述脚本,然后测试它是否有错误。如果发生错误,它将显示errors.txt文件中的错误。

#!/bin/sh

$scriptName

./$scriptname 2> ~/Documents/LinuxLab3/errors.txt

if [ -s errors.txt ];then
        echo "There were errors:"
        cat ~/Documents/LinuxLab3/errors.txt
else
        echo "No errors encountered"
fi

当我跑步时

./scriptTester.sh Trial1.sh

我收到错误

./scriptTester.sh: 5: ./scriptTester.sh: ./: Permission denied

所有脚本均为sudo chmod +rx

1 个答案:

答案 0 :(得分:0)

如果不仅仅是复制粘贴代码的错误,那么我会在代码中看到两个问题。我假设您的第二行应该读取(将参数保存在变量中)

import {Parties} from '../../collections/parties';

然后,在第三行,您拼错了变量 - scriptName=$1 而不是$scriptname

<强>更新

$scriptName
相关问题