Hello! In this bash program, there is an error when i try to execute it.
I am running it on Unix and I used emacs for the text editor
it says:
line 3: [0: command not found
line 9: if[-f ]: command not found
line 10: syntax error near unexpected token `then'
line 10: `then'
-------------------------------
#!/bin/bash
if [ $# != 1 ]
then
echo "Usage: myScript.sh "
exit 1
fi
if [ -f $1 ]
then
awk '
BEGIN {
i=0
flag=0
avg=0
total=0
}
{
tmp =0
count=0
sum=0
flag = 0
for(i=1; i<=2; i++)
{
printf("%s ", $i);
}
for(i=3; i<=NF; i++)
{
tmp = $i + 0
if ($i == 0)
{
flag =1
}
printf("%s ",$i);
if(tmp || flag)
{
sum = sum + tmp
count++
}
}
printf("%d %d", sum, (sum/count) +0.5);
printf("\n");
}
END {
}
' < $1
else
echo "Error: file $1 does not exist"
fi
Please find the right script and following errors could be introduced by you.
1. You have leave space between "if" and "[" not as "if[ $# != 1]". So it should be like this"if [ $# != 1 ]"
2. And the same is in "if[ -f". So it should be like this "if [ -f $1 ]"
3. Use emacs to type the same program with exact spaces as mentioned above and right syntax
Program Screen Shot:
![if[$# != 1 ] then echo Usage: myscript.ah exit 1 fi if -$1 then awk BEGIN flag avg o total-0 tmp =0 count-0 sum-0 flag 0 f](http://img.homeworklib.com/images/662a0b27-8061-42cf-8ba9-612668df4742.png?x-oss-process=image/resize,w_560)
Hello! In this bash program, there is an error when i try to execute it. I am running it on Unix and I used emacs for the text editor it says: line 3: [0: command not found line 9: if[-f ]: command no...
Hello all, I have a c++/unix (bash) question.
I am struggling on starting this assignment. If you could start the
assignment and tell me how to do the rest it would be greatly
appreciated!
(Quick thumbs up answer response if thorough and correct)
Maintain automobile records in a database Write a shell script to
create, view and modify a simple database that contains automobile
records. The shell script has to be done in Bourne shell syntax
(bash as a matter...