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
Two things:
=
signal and the value of the variableIf 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
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.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)
Should be a=
$( ... )
orMaybe by trying to use cut like this: