LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-04-2012, 12:27 PM   #1
Alex92
LQ Newbie
 
Registered: May 2012
Posts: 2

Rep: Reputation: Disabled
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
 
Old 05-04-2012, 12:31 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,393

Rep: Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014Reputation: 2014
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
 
1 members found this post helpful.
Old 05-04-2012, 12:42 PM   #3
Alex92
LQ Newbie
 
Registered: May 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks a lot suicidaleggroll.Problem solved.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
command not found error while executing a shell script SurbhiJain Linux - Newbie 15 07-26-2010 09:18 AM
running shell script: command not found tripat Red Hat 3 04-14-2010 01:21 PM
Shell Scripting Problem: command not found gods_design Programming 3 02-10-2009 11:58 PM
Command not found error - difference in shell? aw_wolfe Linux - Newbie 6 04-20-2005 04:49 PM
command not found (My shell script) Swift&Smart Linux - Software 3 05-15-2004 11:14 PM


All times are GMT -5. The time now is 02:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration