Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Bash script, trying pass variables to "find"

  • 13-02-2010 3:03pm
    #1
    Registered Users, Registered Users 2 Posts: 2,078 ✭✭✭


    Hi,

    I'm looking for log files that may or may not exist, and I don't know exact file names besides. I know they have a 3 digit identifier ($seq) followed by an '_ 'so I'm looking to write a script that will read through my 30+ directorys (5000+ log files) and do a bit of cleaning up.

    I'm trying to use find, as I would normally, but having it search in a directory defined by a variable for files defined by variables, return the value to form an array $LISTS(). (directory names are in an array $JOB[], referenced with variable $x)
    LISTS=(`find ./${JOB[${x}]}/ -name \'*${seq}_*\'`)

    It doesn't work.

    If I use constants instead of variables, it does. I've echoed the variables and the values are good but "find" seems to try and evaluate the command before the variables are converted to real values. I tried \ escaping the quotes.

    Send "you should just use perl" > /dev/null :)


Comments

  • Registered Users, Registered Users 2 Posts: 354 ✭✭AndrewMc


    theCzar wrote: »
    LISTS=(`find ./${JOB[${x}]}/ -name \'*${seq}_*\'`)

    I'd have to see more of the script to see how you're manipulating $x (are you running this in a loop, updating $x each time?). However, it looks like ${seq} is inside single quotes — as far as I can remember this means no variables inside will be expanded. Can you try " instead, or just leave the quotes out altogether?


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    AndrewMc wrote: »
    Can you try " instead

    That's your answer. I think that's safer than not using quotes because that can result in unwanted shell substitution.


  • Registered Users, Registered Users 2 Posts: 2,078 ✭✭✭theCzar


    Thanks for the answer, the double quotes work.

    Sort of annoyed I didn't think to try that before coming on here!


  • Moderators, Arts Moderators Posts: 35,731 Mod ✭✭✭✭pickarooney


    Don't be. Think of all the people who will find the same answer now that you posted the question.


Advertisement