ksh syntax explanation - from mimetool


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh syntax explanation - from mimetool
# 1  
Old 07-26-2005
ksh syntax explanation - from mimetool

Hi

I got this part of the script from the mimetool by Perderabo.
I have difficulty in decyphering the syntax specially lines 4,5 & 9.
Also the test condition in line 3.
Could someone help me on this please.

--------------------------------------
pwentry=$(grep "^$(logname):" /etc/paswd)
((index=0))
while [[ $pwentry = *:* ]] ; do
pwfield[index]=${pwentry%%${pwentry##*([!:])}}
pwentry=${pwentry##*([!:]):}
((index=index+1))
done
pwfield[index]=${pwentry}
myname=${pwfield[4]%%,*}
myaddr=${pwfield[0]}
-------------------------------------------

thanks in advance
Chaandana
# 2  
Old 07-27-2005
That is not exactly my code. You didn't even spell /etc/passwd right. Smilie You might want to look at mimetool again. But anyway, remember that a passwd file entry is data separated by colons, like this...
field1:field2:field3
I wanted those field in an array. So i want to break the fields off one by one in a loop. I need to loop as long as there is at least two fields left. So I test for "*:*". Lets say there are only 3 fields as i show above. At first pwentry is "field1:field2:field3" and index is 0. So that line 4 sets
pwfield[0]=field1
and line 5 sets
pwentry="field2:field3"
This still matched the pattern *:* so we do the loop again and this time pwentry=field3. Now we don't match *:* anymore so we get out. Line 7 picks up that last field. In line 9 I am removing any comma and anything following the comma. That is because the gcos field is comma separated and I want the first sub-field.

That ${variable##pattern} and ${variable%%pattern} stuff has been discussed lots of times, use our search function. Or read "man ksh", it's there too.
# 3  
Old 07-27-2005
MySQL

Perderabo,

Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

ksh code explanation

Hi. Can somebody please explain the following lines of KSH code for me? The code checks all sub directories in a specific location which are numbered (E.g. test_01, test_02 ... etc.), then finds the one with highest number and extracts that number from the dir name into the variable num. I'd just... (9 Replies)
Discussion started by: user052009
9 Replies

2. Shell Programming and Scripting

Help with ksh syntax error Unexpected Fi

Issue resolved, thanks (6 Replies)
Discussion started by: dangell82
6 Replies

3. Shell Programming and Scripting

KSH syntax error

Hi all, Anyone know why I get the error below under ksh? $ EXCLUDES=( $(< "$EXCLUDES_FILE") ) sh: syntax error: `(' unexpected I'm trying to use the above line in a script and it's not working. The guy that gave me the script was running in a linux environment, so I'm thinking this might... (1 Reply)
Discussion started by: mmw
1 Replies

4. Shell Programming and Scripting

KSH - different syntax for function

Hi, I wanted to know what's the difference between the below two syntax used for writing ksh function: e.g. 1 ------ function fn1 { echo "Hello World" } e.g. 2 ------ fn1 () { echo "Hello World" } (4 Replies)
Discussion started by: dips_ag
4 Replies

5. Shell Programming and Scripting

syntax for CAT in ksh

Just want to ask if the below code is correct; if ; then echo "No log found from " $data exit 0 else cat out.txt fi this is to test if the content of out.txt is 0 then message appear that there is no log. Is this correct? (3 Replies)
Discussion started by: harry0013
3 Replies

6. Shell Programming and Scripting

explanation for the syntax

Hi I am new to shell programming, can anyone explain me the following syntax... it could be helpful if it was brief... if (1 Reply)
Discussion started by: chandhar
1 Replies

7. Shell Programming and Scripting

Need explanation for the syntax

Hi it will be very useful for me if anyone gives step by step explanation for the below code: USAGE="check -S dbserver where -S dbserver specifies name of database server -D dbname specifies name of database on database server -U userid specifies name of user for database" ... (1 Reply)
Discussion started by: chandhar
1 Replies

8. Shell Programming and Scripting

Need explanation for the syntax(code)

Hi I am new to shell script programming... want to know the process of the following: if then echo "$0: missing argument for option(s) :$MISSINGOPTARG" echo "usage" $USAGE" exit 1 fi (1 Reply)
Discussion started by: chandhar
1 Replies

9. UNIX for Dummies Questions & Answers

Question about perderabo's MIMETOOL script

Perderabo, I copied the mimetool script and am running it on an HP-UX release 11i, and in most cases it works like a charm. But I ran into the following issue; I extracted data from an Oracle database and formatted the results as a *.csv file so that the user can view it as an excel... (4 Replies)
Discussion started by: perssonc
4 Replies

10. Shell Programming and Scripting

Follow-up w/ Perderabo re: mimetool

This is a follow-up re: this thread As I mentioned, this script works very nicely, thanks again. However, the ASCII data of the 'attached file' also shows below the body of the email message. Do you know of a way to 'disable' the attached text from showing? Although the file is attached,... (3 Replies)
Discussion started by: jwperry
3 Replies
Login or Register to Ask a Question