I'm trying to run those scripts but I keep receiving errors messages:
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
the error message is :
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"
the error message is:
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
the error message is:
stat: missing operand Try `stat --help' for more information. ./scr4: line 8: [: -gt: unary operator expected
any idea how to fix them ?
$()notation$(stat -c %U $filename)which eliminates nesting problems -- use braces on your vars$dir-->${dir}-- considera = $((sum + num))vs.let "a = $sum + $num"${variable}string"set -vx (on), andset +vx (off). This will print the code that is to be executed, and then a 2nd line preceded with+will show the actual command that is run, with values substituted for variable names. While/Until/For loops and nested constructs can be confusing to read at first, focus on the results of the+'d lines. Also addingexport PS4='${LINENO} +>will show you the line number of the current script being executed. Good luck.${var}stringenough that, for consistency, I now always use the${var}form even if a string does not follow.