简体   繁体   中英

Bash shell expansion gives command not found

I am pretty new to bash scripting I am amazed at everything it can do. I have hit a wall, tried a number of different combinations to get this to work and cannot seem to get it.

Any ideas / tips / answers would be greatly appreciated!

The problem: I have a file that gets dropped as part of an ldapsearch script, it contains sAMAccountName and mail attributes. These are on separate lines, I would like to: 1) take a grepped file (grep -E "sAMAccountName|mail") this produces one entry per line and output this as , which i will then feed to postmap hash:/etc/postfix/canonical (ftw).

however! my plans for world domination have been delayed because the statement where i am assigning the output of the command execution to $stuff issues command not found... grrr. Please kind internet bash gurus point out my mistakes please! note not all the code is included, just the piece that is giving me trouble: ref1: Bash regex if statement

#############################
#!/bin/bash
while read line; do

if [[ $line =~ ^sAM ]]; then
 stuff = $( echo "$line" | cut -d\: -f2) #<-- command not found
 echo -n $stuff >> /etc/postfix/tmp-canonical

fi

if [[ $line =~ ^mail ]]; then
 stuff = $( echo "$line" | cut -d\: -f2) #<-- command not found
 echo -n "<tab>$stuff\n" >> /etc/postfix/tmp-canonical

fi

done < "$1"
#end

stuff is interpreted as a command instead of variable assignment because of the space before the equal sign. Remove the space and it should work.

stuff=$( echo "$line" | cut -d\: -f2)

FOUND IT! I just hadn't tried hard enough! Okay here is how i fixed it:

code snippet (the corrected)

STUFF=$(echo "$line" | cut -d\: -f2)

The original -

STUFF = $(echo "$line" | cut -d\: -f2)

The space between STUFF and the "=" was being interpreted, found this article: How to set a variable to the output from a command in Bash?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM