bash $X++ sintax
Neil Watson
tlug-neil-8agRmHhQ+n2CxnSzwYWP7Q at public.gmane.org
Thu May 25 19:25:54 UTC 2006
On Thu, May 25, 2006 at 03:10:41PM -0400, Chris F.A. Johnson wrote:
>> What about the perl
>>operator .= ?
>
> What does that do?
That is the equivalent to ++ only for strings. Example:
$X = "foo";
$Y = "bar";
$word = $X;
$word .= $Y;
print $word
foobar
I think I have it figured out but I'm still missing something. Consider
this script:
#!/bin/bash
# User prefix
USER="sftp"
# Number or users
NUM=5
# Email report recipient
RECIP="nhwatson-CDzewpS4IfcWRvO7F5PPEFaTQe2KTcn/@public.gmane.org"
# Mail messages
MSG="Transfer passwords for today (`date`):"
# Generate passwords for all users
apg -m 10 -M CN -n ${NUM} | {
while read PW; do
X=$(( $X + 1 ))
# Username will be USER+NUM e.g. sftp1
USERNAME=${USER}${X}
# Set password for user
echo $PW | passwd -u $USERNAME --stdin
# Log change for later email
MSG="${MSG} User: $USERNAME Password; $PW"
done
}
echo $MSG #| mail -s "SSH Transfer Password Updates" $RECIP
exit 0
MSG is as expect until is finishes the code block. After that it is reset to
its original state. It's like MSG is scoped differently inside the code block.
I am not aware that bash is scope conscious.
-
Neil Watson | Gentoo Linux
System Administrator | Uptime 15:17:35 up 9:09, 2 users, load average: 0.00, 0.00, 0.00
http://watson-wilson.ca | 2.6.11.4 AMD Athlon(tm) MP 2000+ x 2
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list