LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   shell problem, command not found (https://www.linuxquestions.org/questions/linux-newbie-8/shell-problem-command-not-found-943295/)

Alex92 05-04-2012 12:27 PM

shell problem, command not found
 
Hi all, i'm having a problem at my problem about comparing 2 strings to last if.I'm trying to see if the first word of the file given as a argument is equal to 0 and if so to output a message.Here is my code and thanks in advance
#!/bin/sh

if [ $# -ne 1 ]
then echo "There are some problems with the parameters! Only one allowed!"
elif [ ! -f $1 ]
then echo "$1 does not exist or is not a valid file!"
else
mkdir Laborator
cd Laborator
echo "Make directory"
# Make 10 files
for i in 0 1 2 3 4 5 6 7 8 9 10
do
echo > $i
done
cd -
for i in `cat $1` ;do
j=$(echo $i | cut -c-1)
echo $j;
if ["$j"-eq"0"];then
echo "abcd"
fi
done
fi

suicidaleggroll 05-04-2012 12:31 PM

You need spaces around your terms in the if statement

Code:

$ j=0
$ if ["$j"-eq"0"]; then echo 1; fi
bash: [0-eq0]: command not found
$ if [ "$j" -eq "0" ]; then echo 1; fi
1


Alex92 05-04-2012 12:42 PM

Thanks a lot suicidaleggroll.Problem solved.


All times are GMT -5. The time now is 11:36 AM.