for loop and sed
der.hans
PLUGd at LuftHans.com
Thu Sep 7 22:03:59 MST 2006
Am 07. Sep, 2006 schwätzte Nathan England so:
>
> I have about 50 users in /home
> I want to create a cron job for each user that will run sa-learn on a spam
> file. I have it properly setup for my user, but I want to copy that to each
> other user, then use sed to replace my user name in each file with the proper
> user name.
>
> I did this
>
> for user in '/bin/ls /home'; do
are those backticks?
> cp /var/spool/cron/nengland /var/spool/cron/$user
> sed -i 's/nengland/$user/' $user
sed -i 's/nengland/'$user'/' $user
Single quotes inhibit variable expansion, so you need to get outside the
quotes :).
Just thought I'd point it out because you can't always used double-quote
as Kurt suggested.
You can also leave the quotes off in some circumstances.
http://www.grymoire.com/Unix/Sed.html - Great sed resource.
ciao,
der.hans
> chown $user $user
> done
>
> While it worked, instead of replacing nengland with the username, it literally
> replaced it with '$user'
>
> What is the proper way to do this?
>
> Nathan
>
--
# https://www.LuftHans.com/ http://www.CiscoLearning.org/
# Join the League of Professional System Administrators! https://LOPSA.org/
# "I have faith in debian-legal." -- Ted Gould
More information about the PLUG-discuss
mailing list