Header RSS Feed
 
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Reminder: Do not start with an integer for a variable name in shell
Monday - Mar 31st 2014 - by - (0 comments)

Just had a weird situation, where I wrote a quick and dirty shell script to output the current amount of deferred mails due to smtp error 421 and send an alert. 

I tried to count the different responses, each smtp response holding an integer as value:

421ips=$(mailq | grep -i -c "refused to talk to me: 421 4.7.1 Intrusion prevention active")
-bash: 421ips=11: command not found

421notaccepting=$(mailq | grep -i -c "421 4.3.2 System not accepting network messages")
-bash: 421notaccepting=11: command not found

421rate=$(mailq | grep -i -c "Our system has detected an unusual rate of 421-4.7.0 unsolicited mail")
-bash: 421rate=6: command not found

I was wondering what the hell just happened until I tried a plain simple variable name:

BLA="$(mailq | grep -i -c "refused to talk to me: 421 4.7.1 Intrusion prevention active")"

Here no error occurred. And that's the moment it hit me: Of course!
Do not start the variable's name with an integer (in this case 421). D'oh!

Distractions, distractions... My mind has been wandering all day.

Actually if I would have used vim with the syntax on command, I would have seen that something's off:

Variable name starting with integer

See the $4 turning blue while the rest doesn't? That would have given me a clue.
But as I just created the file, vim didn't know (yet) that it'll be a shell script and therefore couldn't show the syntax highlighting. Only after a close (and save) and reopen with vim the syntax highlights are shown.

 

Add a comment

Show form to leave a comment

Comments (newest first):

No comments yet.

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6937 Days
until Death of Computers
Why?