[GLLUG] shell script question
12 Jul 2002 09:45:23 -0700
Mike Rambo <firstname.lastname@example.org> writes:
> I'm trying to wite a bash shell script that will place a configuration
> file in each users home directory. I can come up with a list of targets
> by using...
> ls /home | grep drwx | cut -d : -f 2 | cut -d \ -f 2
This looks fragile; e.g., take my own /home:
blp@pfaff:~(0)$ ls -l /home
drwxrwxr-x 89 blp blp 8192 Jul 12 09:40 blp/
drwxr-xr-x 5 root root 4096 Jun 13 2001 teams/
drwxr-xr-x 2 timd timd 4096 Jul 6 2001 timd/
Now consider the lines that don't contain any colons at all.
What's wrong with `/home/*'?
> ...which I can direct to a file or whatever. Is there a way to take the
> resulting list and assign or use each item sequentially as a variable in
> a statement something like...
> cp file-i-want /home/$TARGET
> ...to copy this file to potentially many user directories at one time?
for d in `...your command...'; do cp file-i-want /home/$d; done
"Debian for hackers, Red Hat for suits, Slackware for loons."