2014-09-10 80 views
0

我有一個bash函數在我的.bash_profile不返回結果到終端。 當我通過CLI正常運行命令時,返回結果。.bash_profile ldapsearch函數不輸出到終端

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 
} 

運行從bash提示符執行時ldap_check_clenaup TestRecord返回沒有輸出。 TestRecord確實存在,當下面的命令從CLI運行,返回正確的記錄:

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` 

,當我嘗試使用此ldapsearch的和參數作爲一個bash函數只把缺乏出來的情況。

我想這可能與使用「,而不是」爲屬性(!(RMID = *)),但我不確定,請幫助。

+2

你想通過將輸出管道輸出到'tee/dev/tty'來完成什麼? – 2014-09-10 15:32:42

+0

如果我刪除tee/dev/tty,同樣缺少輸出。我試圖通過tty – 2014-09-10 15:33:46

+1

強制重定向到終端(我冒昧給格式化代碼,並且爲了更好的可讀性添加了一些bash換行符。希望我沒有搞砸任何東西) – lxg 2014-09-10 15:36:36

回答

2

您需要使用參數兩邊雙引號是包含$1變量插值不在單引號字符串內部執行

+0

現貨!取而代之的是.bash_profile中的「with」,並且像一個魅力一樣工作,這很奇怪,因爲在CLI中,當我用「,我得到」-bash:!:event not found「發出命令時,返回給ldapsearch querry。什麼會導致cli與bash函數的行爲差異? – 2014-09-10 15:55:20

+0

我剛剛閱讀您引用的http://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash文章。在這種情況下,在CLI中如何處理雙引號*?我儘量保持我的函數儘可能類似CLI使用。 – 2014-09-10 15:58:32

+1

你不需要做任何特別的事情。當一個'*'在雙引號內時,不會執行文件名通配符,'*'將被傳遞給程序(因爲我相信在這種情況下是所需的結果)。 – 2014-09-10 16:14:08