0

I have a bash function in my .bash_profile that is not returning results to the terminal. When I run the command as normal via the CLI results are returned.

ldap_check_cleaup () 
{
ldapsearch -LLL -h itdsvbms.SomeDomain.org -p 389 \
    -D "uid=SomeUser,o=SomeDomain.org" -w SomePassWord -b "ou=People,o=SomeDomain.org"  \
    -s sub '(&(ReservedRMAliases=$1)(!(RMid=*))(RMAliasUpdateDate=12/01/2012 19:02:00)(RMAliasStatus=IN)(status=IN))' |  \
        tee /dev/tty  
} 

running ldap_check_clenaup TestRecord returns no output when executed from the bash prompt. TestRecord does exist and when the following command is run from the CLI, the correct record is returned:

ldapsearch -LLL -h itdsvbms.SomeDomain.org -p 389 -D "uid=SomeUser,o=SomeDomain.org" \
    -w SomePassWord -b "ou=People,o=SomeDomain.org" \
    -s sub '(&(ReservedRMAliases=TestRecord)(!(RMid=***))(RMAliasUpdateDate=12/01/2012 19:02:00)(RMAliasStatus=IN)(status=IN))' | \
        tee /dev/tty`

The lack of out put only happens when I try to use this ldapsearch and the arguments as a bash function.

I think this may be related to using ' instead of " for the attribute (!(RMid=*)) but I am unsure, please help.

lxg
  • 12,375
  • 12
  • 51
  • 73
Evil Genius
  • 1,015
  • 2
  • 10
  • 16

1 Answers1

2

You need to use double-quotes around the argument that contains $1. Variable interpolation is not performed inside single-quoted strings.

nobody
  • 19,814
  • 17
  • 56
  • 77
  • Spot on! replaced the ' with the " in .bash_profile and worked like a charm. It's odd because in the CLI when I issue the command with a ", I get "-bash: !: event not found" returned for the ldapsearch querry. What would is causing the difference in behavior in the cli vs the bash function? – Evil Genius Sep 10 '14 at 15:55
  • I just read the http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash post you referenced. How would one handle a * in double quotes then in this case at the CLI? I try to keep my functions an CLI use as similar as possible. – Evil Genius Sep 10 '14 at 15:58
  • 1
    You shouldn't need to do anything special. When a `*` is inside double quotes, filename globbing won't be performed and the `*` will be passed to the program (as I believe is the desired result in this case). – nobody Sep 10 '14 at 16:14