Is there a way that I can combine the following commands (the last is a zsh function) into a single bash script?find /path/to/directory/*/* ! -name *.js -type f -deletefind /path/to/directory/*/* ! -name *jquery* -type f -deletefind /path/to/directory/*/* ! -name *jquery* -type d -deletefor dir (/path/to/directory/*(/)) rm -f $dir/*.js(OL[2,-1])
Combining multiple functions into a single bash script
shell script
If you simply want to write a script that executes the commands one after the other, you have two real options:Write a bash script, and for the last command, invoke zsh to execute it (have one shell invoke another shell).Write a zsh script which in turn runs the four commands, forgetting about bash.While bash is a very common shell on Linux, there is nothing magical about bash as such. You can just as easily write a zsh script instead; the #! line at the beginning says which program should be used to execute the script.Hence, if you want to go with option 2 above (which I likely would), just make a plain text file that starts with #!/bin/zsh (or wherever zsh happens to be on your system), and is followed by the commands. You'd get something very much like this:#!/bin/zshfind /path/to/directory/*/* ! -name *.js -type f -deletefind /path/to/directory/*/* ! -name *jquery* -type f -deletefind /path/to/directory/*/* ! -name *jquery* -type d -deletefor dir (/path/to/directory/*(/)) rm -f $dir/*.js(OL[2,-1])There shouldn't be anything more than that to it. Note: depending on the idiosyncrasies of zsh, you may or may not need to use a bit more quoting. I prefer to always put quotation marks around variables that are being expanded unless I am positive that it's not needed (and even then often do), just in case.