LinuxQuestions.org
Help answer threads with 0 replies.
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 04-27-2007, 03:59 AM   #1
hottdogg
Member
 
Registered: Aug 2004
Location: aisenodni
Distribution: slackware 64bit ,debian 64bit
Posts: 202

Rep: Reputation: 30
need help regarding my very simple bash script


I'm still very newbie in bash programming...
I made this script to delete something like 'typescript' that cluttering in my home dir and its sub-dirs.
here's the script
Code:
#!/bin/bash

if [ "$0" = "./$1" ] || [ "$#" -ne 1 ] 
then
    echo " usage: $0 [namafile] "
else 
    for x in $(find ./ -follow -name "$1")
    do
	rm -v $x
    done
fi
But i want to make this script 'smarter'.
Currently it can only accept argument with literal pattern.
eg:
Code:
$./myrmscript typescript
It can't accept wildcard. How to make my script accept wildcard,
so i can use this to delete files like foo1,foo2,fooyou.
just by typing
Code:
$./myrmscript foo*
tnx in advance.
 
Old 04-27-2007, 04:26 AM   #2
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
you can use $@. This will expand out your arguments passed in from shell
Code:
for args in $@
...
...
 
Old 04-27-2007, 08:40 AM   #3
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Try
Code:
$./myrmscript foo\*
If neccesary, add more backslashes to taste ;-)

Groetjes,

Kees-Jan
 
Old 05-02-2007, 03:09 AM   #4
hottdogg
Member
 
Registered: Aug 2004
Location: aisenodni
Distribution: slackware 64bit ,debian 64bit
Posts: 202

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by kees-jan
Try
Code:
$./myrmscript foo\*
If neccesary, add more backslashes to taste ;-)

Groetjes,

Kees-Jan
this works like a charm !
even i don't have to edit my script.
tnx.
 
  


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
Simple bash script help zok Linux - General 4 12-15-2006 12:56 PM
Simple bash script Soulful93 Programming 1 06-04-2005 08:26 PM
Simple Bash Script Help njdownes Programming 2 03-05-2005 08:35 AM
Simple Bash Script dmedici Programming 9 12-31-2004 04:48 AM
Help with simple bash script - please tw001_tw Linux - Software 5 12-19-2004 10:02 PM


All times are GMT -5. The time now is 08:35 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration