我正在尝试运行这些脚本,但我不断收到错误消息:
1-
#!/bin/bash
filename=$1
if [ -f $filename ]
then
owner=`stat -c %U $filename`
grep $owner /etc/passwd
if [ $? -eq 0 ]; then
perm=`stat -c %a $filename | head -c 1`
if [ $perm -gt 3 ]; then
cat $filename | grep NOTE
fi
fi
fi
错误信息是:
stat: missing operand Try `stat --help' for more information.
2-
#!/bin/bash
NoSum=$1
sum=0
echo "Please enter $NoSum values one at a time"
for (( i=1; i<=$NoSum; i++ ))
do
echo "Next Value?"
read num
let "a = $sum + $num"
sum=$a
done
echo "The sum is : $sum"
错误信息是:
Please enter values one at a time ./scr3: line 6: ((: i<=: syntax error: operand expected (error token is "<=") The sum is : 0
3-
#!/bin/bash
dir=$1
if [ -d $dir ]
then
perm=`stat -c %a $dir | head -c 1`
if [ $perm -gt 5 ]; then
cd $dir
for file in $dir/*
do
if ! [ -x "$file" ]
then
echo "$file"
fi
done
fi
fi
错误信息是:
stat: missing operand Try `stat --help' for more information. ./scr4: line 8: [: -gt: unary operator expected
知道如何修复它们吗?
最佳答案
程序没有任何问题。您没有提供命令行参数。您必须按以下方式运行它
1 和 3:
./script.sh <filename>
2:
./script.sh <number>
$1
代表第一个命令行参数
关于linux - Bash 脚本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22825717/