将脚本作为输入,执行并测试错误
Take a script as input, execute, and test for errors
我正在尝试制作一个脚本,它采用脚本的名称,执行所述脚本,然后测试它是否有错误。如果发生错误,它将显示 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
如果这不仅仅是复制粘贴您的代码时出错,那么我发现您的代码中存在两个问题。我假设您的第二行应该是(将参数保存在变量中)
scriptName=
然后,在第三行,您拼错了变量 - $scriptname
而不是 $scriptName
。
更新
#!/bin/sh
scriptName=
./$scriptName 2> errors.txt
我正在尝试制作一个脚本,它采用脚本的名称,执行所述脚本,然后测试它是否有错误。如果发生错误,它将显示 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
如果这不仅仅是复制粘贴您的代码时出错,那么我发现您的代码中存在两个问题。我假设您的第二行应该是(将参数保存在变量中)
scriptName=
然后,在第三行,您拼错了变量 - $scriptname
而不是 $scriptName
。
更新
#!/bin/sh
scriptName=
./$scriptName 2> errors.txt