LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-12-2011, 03:06 PM   #1
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Rep: Reputation: Disabled
Problem with rm command in shell script


Greetings,

I have the following script (named overscript.sh) which runs some other scripts:

Code:
#!/bin/bash 

# MUST have dcd and psf in single directory.  ONLY these two files, along with the necessary scripts, 
# should be in the directory


# Insert path of directory containing your .dcd and .psf files 
cd /home/joey/share/3TEST
# Creates the protein and water volmap files
vmd -dispdev text -e makeDxfiles.vmd
# Loop the dxTuber cmd version over the volmap files
./MOD_Loop_Tuber_Script.sh
# Remove original volmap files. Leaves the output volmaps, psf, dcd, vmd scripts, and shell scripts.
rm !(*out.dx|*.psf|*.dcd|*.vmd|*.sh)
# Loads psf, dcd, and new volmap files into VMD
vmd -e load_dx_ak.vmd
Everything works fine up until the rm command. I get the error:
Code:
./overscript.sh: line 14: syntax error near unexpected token `('
./overscript.sh: line 14: `rm !(*out.dx|*.psf|*.dcd|*.vmd|*.sh)'
When I type out the command in the terminal, it works fine. Can anyone tell me what's wrong with the script?

Thanks,
Joe
 
Old 07-12-2011, 03:26 PM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
This works for me:
Code:
find . -not -iname "*out.dx" -and -not -iname "*.psf" \
    -and -not -iname "*.dcd" -and -not -iname "*.vmd" -and \
    -not -iname "*.sh" -type f  -print0 | xargs rm
The problem was with the globbing you tried - "find" is more flexible

Hope this helps,
 
Old 07-12-2011, 05:17 PM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
Have you enabled extended globbing?

Code:
shopt -s extglob
 
1 members found this post helpful.
Old 07-13-2011, 10:41 AM   #4
jdmResearch
LQ Newbie
 
Registered: Jul 2011
Posts: 12

Original Poster
Rep: Reputation: Disabled
Added what MTK said right before the rm command. Worked fine!

Thanks!
 
  


Reply



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
Using shell command output as input in shell script - how to do? EnderX Linux - Newbie 2 06-30-2010 12:46 PM
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
Shell-script should control a piped command -> PROBLEM waldese Linux - General 8 09-29-2006 03:27 AM
Problem with shell script using a variable from a unix command. abefroman Programming 1 05-10-2006 02:14 PM
Odd problem with making a variable the output of a command in a shell script linux=future Programming 3 12-13-2005 09:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:39 AM.

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
Open Source Consulting | Domain Registration