[GLLUG] shell script question

Melson, Paul PMelson@sequoianet.com
Fri, 12 Jul 2002 13:31:30 -0400


To clarify your question about ` or ' or ", here's the rule of thumb
that I use for Bourne/Bash scripting.  Using ` to wrap a command will
represent it's output.  For example, if I want to see if the passwd
executable in my $PATH is setuid, I can type:

# which passwd
/usr/bin/passwd
# ls -l passwd
-r-s--x--x    1 root     root        13536 Jul 12  2000 /usr/bin/passwd

Or, to shorten it, just use:

# ls -l `which passwd`
-r-s--x--x    1 root     root        13536 Jul 12  2000 /usr/bin/passwd

And, to the best of my knowledge, you can use ' and " interchangeably to
indicate the explicit value of something.  The caveat being that the `
and $ characters are ignored (that is, treated like any other
alphanumeric character) when wrapped in a '.  For example (within a
script named myscript.sh):

this command:		echo "Usage: $0 [date]"
will generate:		Usage: myscript.sh [date]
but this command:		echo 'Usage: $0 [date]'
will generate:		Usage: $0 [date]

Clear as mud?  :-)

PaulM

-----Original Message-----
From: Mike Rambo [mailto:mrambo@lsd.k12.mi.us]
Sent: Friday, July 12, 2002 1:08 PM
To: Melson, Paul
Subject: Re: [GLLUG] shell script question


Lots of ways to do this...

But they all seem to revolve around a for loop.

I'm pretty new (like about the last 5-10 days) to shell scripts. I've
learned a lot in a short amount of time but I still get baffled about
the rules regarding what seems to me to be embedding command sequences
in other command sequences (and when to use ` vs ' vs " is another one
that can leave in a tmp directory experimenting ;-).

Your method and the awk method basher suggested both look better than my
command for the reasons Ben Pfaff voiced.

Thanks.


"Melson, Paul" wrote:
> 
> Sure.  Try something like this:
> 
> #!/bin/sh
> HOMEDIR=`find /home -type d -maxdepth 1`
> for TARGET in $HOMEDIR
> do
>   cp /etc/skel/.config $TARGET/.config
> done
> 
> Hope that helps!
> 
> PaulM
> 
> -----Original Message-----
> From: Mike Rambo [mailto:mrambo@lsd.k12.mi.us]
> Sent: Friday, July 12, 2002 12:21 PM
> To: GLLUG List
> Subject: [GLLUG] shell script question
> 
> 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
> 
> ...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?
> 
> Thanks
> 
> --
> Mike Rambo
> mrambo@lsd.k12.mi.us
> _______________________________________________
> linux-user mailing list
> linux-user@egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user

-- 
Mike Rambo
mrambo@lsd.k12.mi.us