LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   need help regarding my very simple bash script (https://www.linuxquestions.org/questions/programming-9/need-help-regarding-my-very-simple-bash-script-549409/)

hottdogg 04-27-2007 02:59 AM

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.

ghostdog74 04-27-2007 03:26 AM

you can use $@. This will expand out your arguments passed in from shell
Code:

for args in $@
...
...


kees-jan 04-27-2007 07:40 AM

Try
Code:

$./myrmscript foo\*
If neccesary, add more backslashes to taste ;-)

Groetjes,

Kees-Jan

hottdogg 05-02-2007 02:09 AM

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 ! :D
even i don't have to edit my script.
tnx.


All times are GMT -5. The time now is 06:43 AM.