Bash 101 Help Please
Matt Graham
danceswithcrows at usa.net
Thu Jul 25 19:02:55 MST 2013
From: Lisa Kachold
[snip]
> Would this work to append to the line [containing 'unique']:
> sed -e 's/unique/ $username/' /etc/samba/smb.conf
In ./smb.conf :
[fred]
valid users = unique fred
# end ./smb.conf
mallory:~$ username=JOEBOB
mallory:~$ sed -e 's/unique/ $username/' smb.conf
[fred]
valid users = $username fred
# end smb.conf
mallory:~$ sed -e "s/unique/ $username/" smb.conf
[fred]
valid users = JOEBOB fred
# end smb.conf
...things in '' aren't subject to bash variable expansion, and running sed on
a file will send that file to stdout. As I wrote in my message to PLUG at
12:35pm today, you probably want something like:
sed -e "s/\(.*valid users.*\)/\1 $username/" -i /etc/samba/smb.conf
...which will edit -in-place /etc/samba/smb.conf so that $username is appended
to lines that contain "valid users".
--
Matt G / Dances With Crows
The Crow202 Blog: http://crow202.org/wordpress/
There is no Darkness in Eternity/But only Light too dim for us to see
More information about the PLUG-discuss
mailing list