0

I ran the following command : ff 'hac-launcher*

[root@foo log]# ff 'hac-launcher*'
./configserver/hac-launcher.log
./odb/hac-launcher.log
.
.

[root@foo log]# type ff
ff is a function
ff ()
{
    find . -type f -name $1 -print
}

However, if I try the same command right in the shell's command line, I get different results.
[root@btpvm0913 log]# find . -type f -name 'hac-launcher*' -print
./configserver/hac-launcher.log
./odb/hac-launcher.log.4
./odb/hac-launcher.log.3
./odb/hac-launcher.log.2
./odb/hac-launcher.log.1
./odb/hac-launcher.log

when I run the command right in the shell prompt, I get more files matching whereas, the same filespec/regex when used within the shell function matched fewer files.

How can I ensure that the function call and the inline command execution both bring in the same results ?

1 Answer 1

2

Your function didn't quote the $1 variable, so the shell performs wildcard expansion on the substituted value. As a result, the actual command it runs is

find . -type f -name hac-launcher.log -print

…based on files in the current directory. (And if the current directory had more than one matching file, it'd cause a syntax error for find.)

To pass the variable's value unaltered, use "$1".

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .