0

i'm new here, and i wanted to understand why my programm doesn't work. Can you help me ? thank you

Error

./mytry.sh: line 28: syntax error near unexpected token `fi'
./mytry.sh: line 28: `fi'
!/bin/sh

echo "find?"
read find 

if [ -z find ];
then 
echo "Ok"
fi

if [ ! -z $find ];
then
echo " You are in $(pwd)"
echo " I'm searching "

for element in $(ls)
do
echo $element

if [ -d $ element ];
then 
echo $element "exist and is not empty"
fi 
fi
done 
2
  • 1
    if [ -d $ element ]; => if [ -d $element ]; use www.shellcheck.net to validate it Commented Nov 20, 2014 at 7:02
  • close the for loop before if block Commented Nov 20, 2014 at 7:03

2 Answers 2

1

There were two syntax based mistakes. The shebang was written wrongly and the fi in the last line should come after done.

#!/bin/sh

echo "find?"
read find 

if [ -z find ];
then 
echo "Ok"
fi

if [ ! -z $find ];
then
echo " You are in $(pwd)"
echo " I'm searching "

for element in $(ls)
do
echo $element

if [ -d $ element ];
then 
echo $element "exist and is not empty"
fi 
done 
fi

Above is the corrected script.

Sign up to request clarification or add additional context in comments.

Comments

0

!/bin/sh

echo "find?" read find

if [ -z find ];
then 
 echo "Ok"

fi

if [ ! -z $find ]; then echo " You are in $(pwd)" echo " I'm searching "

for element in $(ls)
do
  echo $element

  if [ -d $ element ];
  then 
     echo $element "exist and is not empty"
  fi 
done 

fi #should close after for loop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.