shell - Loop with variable in bash script -


i deploy website using post-receive git hook. within hook use yui compressor minify js , css files:

export temp=/var/www/example.com git_work_tree=/var/www/example.com git checkout master -f #minify mit yui (cd $temp/css && min style.css && rm style.css && mv style.min.css style.css) (cd $temp/addons/css && min bootstrap.css && rm bootstrap.css && mv bootstrap.min.css  (cd $temp/js && min script.js && rm script.js && mv script.min.js script.js) (cd $temp/addons/js && min startup.js && rm startup.js && mv startup.min.js startup.js) 

now not specify exact files, search js , css files through folders in $temp , repeat minify procedure each time.

could 1 me right loop , search-syntax case? thanks!

just guess here, constructs this?

find $temp -name \*.css -exec sh -c 'f="{}"; min "$f" && mv "${f%.css}.min.css" "$f"' \; 

the idea find command finds css files, executes min , mv commands. no need rm, mv overwrite.

you can figure out equivalent line javascript files. :-)

note haven't tested this, don't use min, isn't question minifying or yui, it's question how execute command on multiple files in directory tree.

update:

you can skip files putting logic find conditions:

find $temp -name \*.js -and -not -name \*.min.js -exec ... 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -