shopt

Match all files under all nested directories with shell globbing

…衆ロ難τιáo~ 提交于 2019-12-03 10:55:07
问题 Is there a way to use shell globbing to identify nested directories? so if I have dir/dir1/dir2/dir3/dir4/dir5/.. and I have files under all of them, what is the equivalent globbing pattern to match all files under all directories, similar to - for example - ls -R 回答1: In Bash 4, with shopt -s globstar , and zsh you can use **/* which will include everything except hidden files. You can do shopt -s dotglob in Bash 4 or setopt dotglob in zsh to cause hidden files to be included. In ksh, set -o

Match all files under all nested directories with shell globbing

a 夏天 提交于 2019-12-03 01:22:59
Is there a way to use shell globbing to identify nested directories? so if I have dir/dir1/dir2/dir3/dir4/dir5/.. and I have files under all of them, what is the equivalent globbing pattern to match all files under all directories, similar to - for example - ls -R In Bash 4, with shopt -s globstar , and zsh you can use **/* which will include everything except hidden files. You can do shopt -s dotglob in Bash 4 or setopt dotglob in zsh to cause hidden files to be included. In ksh, set -o globstar enables it. I don't think there's a way to include dot files implicitly, but I think **/{.[^.],}*

Make shopt change local to function

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-30 17:10:14
I'm trying to write a bash function that uses nocasematch without changing the callers setting of the option. The function definition is: is_hello_world() { shopt -s nocasematch [[ "$1" =~ "hello world" ]] } Before I call it: $ shopt nocasematch nocasematch off Call it: $ is_hello_world 'hello world' && echo Yes Yes $ is_hello_world 'Hello World' && echo Yes Yes As expected, but now nocasematch of the caller has changed: $ shopt nocasematch nocasematch on Is there any easy way to make the option change local to the function? I know I can check the return value of shopt -q but that still means

Unable to enable globstar in Bash 4

本秂侑毒 提交于 2019-11-29 10:03:21
I put the following unsuccessfully to my .bashrc shopt -s globstar I am trying to test the command in action by ls **/*.c and by comparing it to ls */*/*.c How can you enable globstar in Bash 4? Hmm. shopt -s globstar should work. To debug, make sure you are running Bash 4: $SHELL --version Then check the setting of globstar : shopt globstar If it is unset, try setting it manually: shopt -s globstar Now see if that works. If it does, you might want to look into why your .bashrc isn't working. Did you remember to restart you shell after editing your .bashrc , or load it with . .bashrc ? 来源:

What do double-asterisk wildcards mean?

隐身守侯 提交于 2019-11-28 05:40:47
I've tried the following command but I am having trouble interpreting it: ls ** but I'm not sure exactly what it is outputting and why that is the result. Keith's answer is the correct one. Refer there. Consider the following directory tree: folderA ├── file1 ├── file2 └── folderB ├── file3 └── folderC ls will list all objects in the current folder: $ ls file1 file2 folderB ls * will list all objects in the current folder and in addition one more level recursively $ ls * file1 file2 folderB: file3 folderC The second * in ls ** is not relevant in most of the cases since shell expands the

Unable to enable globstar in Bash 4

微笑、不失礼 提交于 2019-11-28 03:32:38
问题 I put the following unsuccessfully to my .bashrc shopt -s globstar I am trying to test the command in action by ls **/*.c and by comparing it to ls */*/*.c How can you enable globstar in Bash 4? 回答1: Hmm. shopt -s globstar should work. To debug, make sure you are running Bash 4: $SHELL --version Then check the setting of globstar : shopt globstar If it is unset, try setting it manually: shopt -s globstar Now see if that works. If it does, you might want to look into why your .bashrc isn't

What expands to all files in current directory recursively?

瘦欲@ 提交于 2019-11-26 19:54:48
I know **/*.ext expands to all files in all subdirectories matching *.ext , but what is a similar expansion that includes all such files in the current directory as well? This will work in Bash 4: ls -l {,**/}*.ext In order for the double-asterisk glob to work, the globstar option needs to be set (default: on): shopt -s globstar From man bash : globstar If set, the pattern ** used in a filename expansion con‐ text will match a files and zero or more directories and subdirectories. If the pattern is followed by a /, only directories and subdirectories match. Now I'm wondering if there might

How to skip the for loop when there are no matching files?

本小妞迷上赌 提交于 2019-11-26 15:33:40
When I loop through all the files starting by foo I do for f in foo* ; do echo "result = $f" ; done The problem is when no file start by foo I get: result = foo* Meaning that the loop is executed once, even if no file start by foo . How is this possible? How can I loop through all files (and not loop at all if there is no file)? You can stop this behaviour by setting nullglob : shopt -s nullglob From the linked page: nullglob is a Bash shell option which modifies [[glob]] expansion such that patterns that match no files expand to zero arguments, rather than to themselves. You can remove this