Find the answer to your Linux question:
Results 1 to 3 of 3
Hey, so i have a function in my bashrc that i use to shred files recursively. it's something like this. Code: find "$1" -name "$2" -exec shred -uzvn 6 '{}' ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2010
    Posts
    21

    Pass wildcards as parameters.


    Hey, so i have a function in my bashrc that i use to shred files recursively. it's something like this.


    Code:
    find "$1" -name "$2" -exec shred -uzvn 6 '{}' \;

    it works fine if i pass it parameters like:

    Code:
    $ function ~/ foo*
    but when i pass it say a parameter like

    Code:
    $ function ~/ *

    it will lift a file name out of my current working directory and pass it as a parameter. so essentially, it tries to find that erroneous file name in the directory specified. how do i prevent this without using any special input?

    EDIT: it appears if i pass the parameter as a literal, ie with 'single quotes' all works fine, but is there any way to achieve this solely inside the script?


    thanks.
    Last edited by TheJanitor; 10-20-2010 at 02:32 AM.

  2. #2
    Linux Newbie
    Join Date
    Mar 2010
    Posts
    152
    Quote Originally Posted by TheJanitor View Post
    EDIT: it appears if i pass the parameter as a literal, ie with 'single quotes' all works fine, but is there any way to achieve this solely inside the script?
    No - the * token is expanded by the shell before your program gets hold of it, so you cannot see it. Furthermore, you probably don't really want to do this - as you've found out, there's a way to explicitly bypass this behaviour, and subverting what users expect the shell to do normally will only lead to confusion.

  3. #3
    Just Joined!
    Join Date
    Jun 2010
    Posts
    21
    yeah thanks, it was a stupid question really. thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •