Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case-insensitive Glob on zsh/bash

Tags:

linux

bash

zsh

glob

I need to list all files whose names start with 'SomeLongString'. But the case of 'SomeLongString' can vary. How?

I am using zsh, but a bash solution is also welcome.

like image 626
Agnel Kurian Avatar asked Oct 01 '08 09:10

Agnel Kurian


2 Answers

ZSH:

$ unsetopt CASE_GLOB 

Or, if you don't want to enable case-insensitive globbing in general, you can activate it for only the varying part:

$ print -l (#i)(somelongstring)* 

This will match any file that starts with "somelongstring" (in any combination of lower/upper case). The case-insensitive flag applies for everything between the parentheses and can be used multiple times. Read the manual zshexpn(1) for more information.

UPDATE Almost forgot, you have to enable extendend globbing for this to work:

setopt extendedglob 
like image 124
jkramer Avatar answered Oct 02 '22 08:10

jkramer


bash:

shopt -s nocaseglob
like image 23
Jacek Szymański Avatar answered Oct 02 '22 07:10

Jacek Szymański