Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected bash directory listing with *

I have a issue with case sensitive directory listing in my bash. for example

   $ touch  nohupa nohuPb
   $ ls nohup*
   nohupa  nohuPb

However I do expect it only list nohupa not nohuPb. because nohuPb has capital P. I don't know what variable in my .bashrc set that * works ignore case.

Any idea ?

like image 295
ARH Avatar asked Jan 12 '12 00:01

ARH


People also ask

What does [- Z $1 mean in Bash?

$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.

What is $@ in Bash?

bash [filename] runs the commands saved in a file. $@ refers to all of a shell script's command-line arguments. $1 , $2 , etc., refer to the first command-line argument, the second command-line argument, etc.

What does $$ do in shell?

The $$ variable is the PID (Process IDentifier) of the currently running shell. This can be useful for creating temporary files, such as /tmp/my-script. $$ which is useful if many instances of the script could be run at the same time, and they all need their own temporary files.

What does $var mean in Bash?

In the bash shell, ${! var} is a variable indirection. It expands to the value of the variable whose name is kept in $var . The variable expansion ${var+value} is a POSIX expansion that expands to value if the variable var is set (no matter if its value is empty or not).


2 Answers

It's nocaseglob that causes that.

nocaseglob
If set, bash matches filenames in a case-insensitive fashion when performing pathname expansion (see Pathname Expansion above).

testing

$ touch fooab fooAb
$ ls
fooAb fooab
$ shopt -s nocaseglob
$ ls fooa*
fooAb fooab
$ shopt -u nocaseglob
$ ls fooa*
fooab
like image 94
c00kiemon5ter Avatar answered Oct 16 '22 16:10

c00kiemon5ter


Looks like your shell has the nocaseglob set. You can unset it by using a shell built-in called shopt. Use -s option to enable it and -u option to disable it.

For more reference you can visit here.

like image 37
jaypal singh Avatar answered Oct 16 '22 16:10

jaypal singh