1

I'm trying to use mkdir command in a bash script using a "*" wildcard. Full code is: mkdir -p $EXTRACTDIR/$CV_NAME*/release

It supposed to create a folder "release" in an existing "OpenCV-2.2.0" folder. Two computers does exactly that and the third creates a folder OpenCV*/release, and I can't figure out why.

Thnx for your help

Royi Freifeld
  • 629
  • 2
  • 11
  • 31

2 Answers2

3

The find command is a very useful command indeed, especially when using the -exec option. I whole heartedly recommend reading up on it further.

find ./$EXTRACTDIR -type d -name $CV_NAME\* -exec mkdir {}/release \;

{} translates the result of the search into the mkdir comand. the parents option for mkdir ( -p ) is not needed because the folder must exist in order to be found.

dax
  • 10,779
  • 8
  • 51
  • 86
thomas-peter
  • 7,738
  • 6
  • 43
  • 58
2

On the third computer "OpenCV-2.2.0/release" doesn't exist, so wildcard matching will fail and will result in a string where * is untouched.

cd $EXTRACTDIR/$CV_NAME*; mkdir release

or

mkdir `echo $EXTRACTDIR/$CV_NAME*`/release 

if you have multiple $CV_NAME* directories, you have to use a loop.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176