1

This question is basically a duplicate of this: https://askubuntu.com/questions/91740/how-to-move-all-files-in-current-folder-to-subfolder

But instead I'm asking how to do it in the Mac OS X terminal with oh-my-zsh.

My issue with the solutions given is they don't seem to work in my terminal (replacing the folder "new" in the question with "oldCodeBase" here)

[~/Sid/Moonshine_Machine, 127, master+3]: mv !(oldCodeBase) oldCodeBase
zsh: number expected

What is the number its expecting here?

Moving to the other suggested solution was to use the shopt command.

But I don't seem to have the shopt command available for use:

~/Sid/Moonshine_Machine, 1, master+3]: shopt -s extglob dotglob
 zsh: command not found: shopt

So at this point neither solution seems to be working.

EDIT:

I found that "setopt" in zsh appears to be a comparable command to "shopt" but leads to the following issue

[~/Sid/Moonshine_Machine, 127, master+3]: setopt -s extglob dotglob
setopt: no such option: extglob

2 Answers 2

3

!(pattern) is a ksh glob operator. shopt is a builtin command of the bash shell to enable one of its options (the ones that are not enabled with set -o). bash's extglob option enables a subset of ksh extended glob operators.

In zsh, negation is with the ^ extendedglob operator as @mdmay74 has already shown and zsh has only one set of options all toggled with set -o / set +o (historically setopt / unsetopt). So you'd use:

set -o extendedglob
mv -- ^oldCodeBase(D) oldCodeBase

Note:

  • -- is needed in case there are file names that start with -
  • (D) is needed to also move hidden files (in bash, you'd use shopt -s dotglob).

zsh also has a kshglob option to enable ksh's extended globs. But since those are more cumbersome to use than zsh's own extended glob operators, you'd generally only use that as part of the ksh emulation (emulate ksh) used to help interpret scripts written for ksh.

set -o kshglob
mv -- !(oldCodeBase)(D) oldCodeBase

(note that !(oldCodeBase) alone wouldn't work unless you also disabled the bareglobqual option as otherwise (oldCodeBase) would be taken as a glob qualifier).

More generally, you can't assume that one thing that works in one language will work the same in another language, unless that thing is from a standard or common heritage that they both share. bash and zsh both have Bourne, Korn and Csh heritage, each have a mode in which they try to be POSIX compliant and have also copied some features from each other, but their syntax is generally different.

1

In the link that you referenced, reading the accepted answer there: in the comments that follow it, one person asks what the equivalent is for zsh, and @MrT responds with:

setopt extendedglob to set the extended glob mode in zsh. ^ is the exclusion symbol, so mv ^new new would do the trick. then to see all the options set in zsh you can use setopt and to disable extended glob mode you can do unsetopt extendedglob

I would have put this in a comment, but I am not yet able to do that... :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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