Sponsored Content
Top Forums Shell Programming and Scripting how to find the value of a variable in zsh? Post 302523919 by ygemici on Friday 20th of May 2011 09:11:20 AM
Old 05-20-2011
scripts try to guess what they are doing this..
first script calls the second script (batmon.zsh)
and batmon.zsh exec executes in first script with exec (you can think so batmon script replaced in first script and executes batmon.zsh with 20[0-9][0-9]-* parameter --> * expands to pattern match )
Code:
exec zsh batmon.zsh 20[0-9][0-9]-* > events.txt 2> stats.txt

as result batmon.zsh is running with "20[0-9][0-9]-*"

Code:
 
* while [ "$#" -gt 0 ] --> if argument count is greater than 0 then loop executes..so if there is an argument then go on in while loop..
so if there is any (folder) file matches pattern with "20[0-9][0-9]-*" in local dir in where script executes , then loop runs.
 
# ls -ld 20[0-9][0-9]-*
drwxr-xr-x 2 root root 4096 2011-05-20 15:16 2011-05-15 20:10:10
drwxr-xr-x 2 root root 4096 2011-05-20 14:47 2011-05-18
drwxr-xr-x 3 root root 4096 2011-05-20 15:35 2011-05-20
 
so our second script executes like this--> # ./batmon.zsh "2011-05-15 20:10:10" 2011-05-18 2011-05-20 

* ./basename.exe "$1" --> in this state , for examle our argument gets "2011-05-20" "2011-05-18" and "2011-05-15 18:00:00" if there are in there.
if you pattern like this , basename is unnecassary but i dont know about the format or i dont know what script owner intended for this.
however if our parameter "2011-20-25/20:00:00" after basename then our variable is "2011-20-25"..
 
* DAY="${DAY[0,4]},${DAY[6,7]},${DAY[9,10]}" --> this gets 0-4 and 6-7 and 9-10 chars with separated a comma.
 
* while read LINE ; do .... ; done <"$1/LogFile.txt" --> if our first argument  "2011-05-20" , 
it looks LogFile.txt in first argument dir then redirects to stdinput to LogFile.txt for while statement so all readings happens from LogFile.txt.
 
# find -type d -name "20[0-9][0-9]-*" |xargs -d'\n' ls -1
./2011-05-15 20:10:10:
LogFile.txt
./2011-05-18:
LogFile.txt
./2011-05-20:
LogFile.txt
 
# more LogFile.txt  ( all contents are completely predict )
Thu 20:10:10:0000000000000000345
Sun 22:10:10:0000000000000125651
 
 * TIME="${LINE[5,12]}"
   TIME="${TIME[0,2]},${TIME[4,5]},${TIME[7,8]}"
   echo -e "${DAY},${LINE[0,2]},${TIME},${LINE[14,99]}\r"
in this, we read a line from LogFile.txt and split format to like above and write to output.txt with 
`done > output.txt` in last line of the first while.
 
* for example if we think to read the line below
Thu 20:10:10:0000000000000000345  
   TIME="${LINE[5,12]}"  --> 20:10:10
   TIME="${TIME[0,2]},${TIME[4,5]},${TIME[7,8]}"  --> 20,10,10
   echo -e "${DAY},${LINE[0,2]},${TIME},${LINE[14,99]}\r" --> 2011-05-20,Th,20,10,10,0000000000000000345
 
* shift  --> if our arguments (parameters) are ["2011-05-15 20:10:10" 2011-05-18 2011-05-20 ] . after shift then $1 --> 2011-05-18
another shift then $1 --> 2011-05-20 and then...so it shifts the parameters to left.
 
* ./gawk.exe -F "," -f batmon.awk < output.txt --> extract lines according to batmon.awk from output.txt


regards
ygemici
This User Gave Thanks to ygemici For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

tutorials about zsh

hi there I'm looking for tutorials about zsh (beginners to experts) can you give me addresses please? thx a lot (3 Replies)
Discussion started by: SpY974
3 Replies

2. UNIX for Dummies Questions & Answers

Z-shell (zsh)

Z-shell (zsh) anyone use it and how do ya like it? (1 Reply)
Discussion started by: Bodhi
1 Replies

3. UNIX for Dummies Questions & Answers

question about zsh

hi, In bash, $ bind -P | grep yank-last yank-last-arg can be found on "\M-.", "\M-_". this allows me to press ALT key and the period (.) to yank the last argument of the previous command line into the current command line. How can I get the same behavior in zsh ? Thanks ... (0 Replies)
Discussion started by: Andrewkl
0 Replies

4. Shell Programming and Scripting

Using zsh

Hi all i am forced to use tcsh at work but i want to use zsh, so i have added this to my .cshrc if (! $?STARTTCSH) then if ("$tty" != "" && -x /bin/zsh) exec /bin/zsh exit endif but this now stopped me going back to tcsh if i need to, is there a way to do this, i would... (7 Replies)
Discussion started by: ab52
7 Replies

5. Shell Programming and Scripting

zsh and host completion

Hi there is there a way i can add to my .zshrc so that when i type rsh <tab> it takes the name for a list of hosts i know it looks in .ssh/know_hosts but i want it for rsh and for a list that i supply thanks A (4 Replies)
Discussion started by: ab52
4 Replies

6. Shell Programming and Scripting

zsh, prompt, variable expansion, ANSI color sequences

Hi! I am using latest ZSH and I have setopt prompt_subst I have a global hash array variable which contains some color definitions with color names as keys and 256-color ANSI codes (with %{ and %}) as values, eg %{\ePS1="$FG Hello World (%M) > " or PS1=$'$FG Hello World (%M) > ' then it... (3 Replies)
Discussion started by: galanom
3 Replies

7. UNIX for Dummies Questions & Answers

ZSH Colors on AIX7

I'd put together a zshrc for use on Linux & AIX 5/6 at another shop that worked fine, but when I tried to put it on here it messes up the colors for some reason I can't understand. I used Phil's ZSH prompt for starters, and everything worked before, and still does on Linux, but isn't working on... (0 Replies)
Discussion started by: Vryali
0 Replies

8. Shell Programming and Scripting

Can I do this without eval? (zsh)

I have in one shell variable, op, a string which represents a "test operator" in a ] construct, for instance -d or -n or -s, an in another shell variable, arg, some arbitrary string. What I want to achieve, is basically this: #This is INCORRECT code. I just want to get you the idea, what I'm... (7 Replies)
Discussion started by: rovf
7 Replies

9. Shell Programming and Scripting

Zsh array -a vs. -A question

Inside a zsh function, I create a local array with local -a arrayname and a local associative array with local -A arrayname. I also can create an array using set, like this: set -A arrayname value1 value2 value3In this form, I can not explicitly declare that an array is associative or... (2 Replies)
Discussion started by: rovf
2 Replies
All times are GMT -4. The time now is 06:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy