Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am writing a bash script and need to cd into a directory, but the directory name is somewhat dynamic. It always begins with package-{then dynamic version}. How do I script this in bash?

cd package-

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

I'm not sure I get your requirement fully.

What about cd package-*? If there are several matches, which one would you like to choose?

share|improve this answer
add comment

If there is only one such directory in that directory, you could do

cd package-*
share|improve this answer
add comment

You could try this, however it would break if you have more than one folder..

#!/bin/bash

find . -type d -name package* -exec cd {} \;
Do something else
share|improve this answer
    
I really doubt you can change dir that way –  hmontoliu May 20 '11 at 20:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.