LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-03-2012, 03:02 PM   #1
pierceogden
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Rep: Reputation: Disabled
script crashes on done command - error [ : : missing ]


Not totally sure how newbie this, but I've only been using linux for like 3 months, so I'm a newbie to this. I have a loop that iterates through a parent directory, and looks for a file. If that file exists in .gz format, it is supposed to unzip it, so I can do stuff to it. Heres my code:
Code:
printf "pdb   uniprot     #ligands \n"
echo '-----------------------'


while read pdbs
do
	cd rn$pdbs
	while read uni
	do
		printf $pdbs
		printf "  "
		cd run.$uni
		printf $uni
		printf "   "
		cd 1.A
		while [ -s test.eel1.gz]
		do
			gzip -d *.gz
		done 
	
		#if [ -a 1.A/test.eel1 ]
		#then	
			grep -i 'remark c' test.eel1 > 	out.txt
			wc -l out.txt > a
			awk '{print $1}' a
		#fi
		#if [ ! -s 1.A/test.eel1]
		#then
		#	continue
	#fi
		#cd ..
		
		#awk '{print $5}'
		printf "\n"
		cd ../..
	done < uni_codes.txt
	
	

cd ..



done < $1
Output looks like this :

Code:
pdb   uniprot     #ligands 
-----------------------
2h7l  P0A5Y6   [: 48: missing ]
500

3e37  Q8K2I1   [: 48: missing ]
501

1bcd  P00918   [: 48: missing ]
505
It is printing the right stuff, but my table is getting messed up ( the 500 number should be under #ligands heading). SO basically my code sort of works, but this error message is making it useless. Sorry my code looks like crap, but hopefully someone can help! Line 48 is where the "done" statement is. Thanks!!

Last edited by pierceogden; 04-03-2012 at 03:03 PM. Reason: Forgot to mention something
 
Old 04-03-2012, 03:07 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Code:
		while [ -s test.eel1.gz]
should be changed to

Code:
		while [ -s test.eel1.gz]
whitespace matters a lot here, as it's just a bunch of independent commands working together, rather than a complete language.
 
Old 04-03-2012, 03:16 PM   #3
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,561

Rep: Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127Reputation: 2127
Quote:
Originally Posted by acid_kewpie View Post
Code:
		while [ -s test.eel1.gz]
should be changed to

Code:
		while [ -s test.eel1.gz]
whitespace matters a lot here, as it's just a bunch of independent commands working together, rather than a complete language.
I believe you mean this:
Code:
		while [ -s test.eel1.gz ]
 
Old 04-03-2012, 03:28 PM   #4
pierceogden
LQ Newbie
 
Registered: Apr 2012
Posts: 10

Original Poster
Rep: Reputation: Disabled
I figured it out! using for loop instead of if, and saving the output!!! any tips on how to make my scripting better is still appreciated!
 
Old 04-03-2012, 03:31 PM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by suicidaleggroll View Post
I believe you mean this:
Code:
		while [ -s test.eel1.gz ]
Oh FFS! thanks!
 
Old 04-03-2012, 03:36 PM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Quote:
Originally Posted by acid_kewpie View Post
Oh FFS! thanks!
ROFL

Even the [GM]ods are fallible
 
Old 04-05-2012, 01:21 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,837

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Here's some general advice:

1)
QUOTE ALL OF YOUR VARIABLE SUBSTITUTIONS. You should never leave the quotes off a parameter expansion unless you explicitly want the resulting string to be word-split by the shell (globbing patterns are also expanded). This is a vitally important concept in scripting, so train yourself to do it correctly now. You can learn about the exceptions later.

http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes


2)
Assuming you're using bash, it's recommended to use ((..)) for numerical tests, and [[..]] for string tests and other complex expressions. Don't use the old [..] test unless you specifically need POSIX-style portability.

http://mywiki.wooledge.org/ArithmeticExpression
http://mywiki.wooledge.org/BashFAQ/031
http://wiki.bash-hackers.org/commands/classictest
http://wiki.bash-hackers.org/syntax/...nal_expression


3)
The printf command syntax is:

Code:
printf '<format>' input input input
Where the <format> is any text string you want, with "%x"-style parameters inserted wherever you want the input strings to appear. Ideally you should have one parameter for each input value, but printf will operate as many times as necessary to consume all the inputs.

"printf '%s\n'" is equivalent to echo, for example.

http://wiki.bash-hackers.org/commands/builtin/printf

So if you only want to print the raw string, followed by a newline, then just use echo. For fancier layout work, learn how to use printf's format strings.


4)
gnu grep has a "-c" option for directly counting the number of matching lines. No need to use a text file and wc. And even if you wanted to use wc, you could still skip the file and pipe the output of grep directly into it.

And no matter what, the "a" file and awk read appear to be completely superfluous.

Code:
grep -ic 'remark c' test.eel1

grep -i 'remark c' test.eel1 |	wc -l
 
  


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
vncpasswd command giving a missing shared object file error analog_match Linux - Newbie 1 02-01-2012 12:50 AM
debian apt-get upgrade gone bad, missing command files, /dev error? lxa2xjj Linux - Software 3 03-05-2010 06:04 AM
aubio make script returning missing libjack.so.0 error on opensuse10.2 :( chickenlinux Linux - Software 4 10-18-2008 09:42 AM
Error with xdm's configure script and missing pkg-config files julz_51 Linux - Software 0 02-22-2006 10:55 AM
Error while running .bin script: missing libXp.so brunnopessoa Linux - Software 2 10-22-2004 09:41 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:12 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