Results 1 to 8 of 8

Thread: Using find in a bash script ?

  1. #1
    Join Date
    Dec 2010
    Beans
    Hidden!

    Using find in a bash script ?

    I mostly/always use find with -iname and directory as . So I want to make a bash script to do this so how will I get the search string into the bash script?

    So here the value of x will change every time I run the script so how will I get the value of x into the script?
    Code:
    ~!/bin/bash/ 
    find . -iname "*x*"
    Sorry if the question is hard to understand
    Ab Aeterno Scientia Potentia est

    http://thevoid.in/

  2. #2
    Join Date
    Nov 2006
    Location
    40.31996,-80.607213
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Using find in a bash script ?

    Code:
    #!/bin/bash 
    find . -iname "$1"
    Last edited by Dr Small; January 24th, 2011 at 02:25 AM.
    "Security lies within the user of who runs the system. Think smart, live safe." - Dr Small
    Linux User #441960 | Wiki: DrSmall

  3. #3
    Join Date
    Jan 2008
    Location
    Manchester UK
    Beans
    13,573
    Distro
    Ubuntu

    Re: Using find in a bash script ?

    Putting a / at the end of #! /bin/bash can cause errors.

  4. #4
    Join Date
    Dec 2010
    Beans
    Hidden!

    Re: Using find in a bash script ?

    Quote Originally Posted by Dr Small View Post
    Code:
    #!/bin/bash/ 
    find . -iname "$1"
    Can you please explain? The script ?
    Ab Aeterno Scientia Potentia est

    http://thevoid.in/

  5. #5
    Join Date
    Jul 2009
    Location
    London
    Beans
    1,480
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Using find in a bash script ?

    theres not really much to explain, $1, $2, $3 etc. contain the values passed as arguments on the command line when you run a command.

    so if you run a script like so:
    Code:
    ./yourscript /home/you/somedirectory someotherparameter
    then in your script $1 would contain the value /home/you/somedirectory, and $2 would contain someotherparameter

  6. #6
    Join Date
    Mar 2007
    Location
    Denver, CO
    Beans
    7,958
    Distro
    Ubuntu Mate 16.04 Xenial Xerus

    Re: Using find in a bash script ?

    And $0 would be the name of the script!!

  7. #7
    Join Date
    Dec 2010
    Beans
    Hidden!

    Re: Using find in a bash script ?

    Thanks !!
    Ab Aeterno Scientia Potentia est

    http://thevoid.in/

  8. #8
    Join Date
    Nov 2006
    Location
    40.31996,-80.607213
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Using find in a bash script ?

    Putting a / at the end of #! /bin/bash can cause errors.
    Yeah, I didn't mean to do that... :S
    "Security lies within the user of who runs the system. Think smart, live safe." - Dr Small
    Linux User #441960 | Wiki: DrSmall

Tags for this Thread

Bookmarks

Posting Permissions

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