Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wrote following line in my script , but it not assigning any value to variable a

a= grep -n mark /etc/samba/smb.conf |cut -d: f1

I aspect line number where mark string present in smb.conf in variable a. But value of variable is null. What may be the issue

share|improve this question
up vote 10 down vote accepted

Two things:

  1. There can be no spaces between name of the variable, the = signal and the value of the variable
  2. If you want to put the results of a command or series of commands on a variable, you must enclose it on $(command) or old style backticks. Both lines below are correct and do the same thing:


So your line must be

a=$(grep -n mark /etc/samba/smb.conf |cut -d: f1)

There are some differences on how to concatenate the use of backticks or new style $(), check this question on SO to see a good response.

share|improve this answer
+1. I recommend putting the delimiter character in single quotes, too: -d':'. It's not needed here, but it's a good habit to have. – SmallClanger Mar 9 '11 at 13:06
a=`grep -n mark /etc/samba/smb.conf |cut -d: -f1`
share|improve this answer

Try this instead

a=$(grep -n mark /etc/samba/smb.conf |cut -d: f1)

Or instead of the $() you could use backticks (which here turn on the nice code look)

share|improve this answer

Should be a=$( ... ) or

a=` … `
share|improve this answer

Maybe by trying to use cut like this:

a=`grep -n mark /etc/samba/smb.conf |cut -d: -f1`
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.