Sponsored Content
Full Discussion: Shell script explanation
Top Forums Shell Programming and Scripting Shell script explanation Post 303012283 by rdrtx1 on Thursday 1st of February 2018 05:06:41 PM
Old 02-01-2018
The script tries to count how many times the input does not contain the letter a then does not contain the letter B. The while loop does not stop though. The second grep should direct to /dev/null (the slash is missing). There should also be a space after echo. A slight change could be:
Code:
i=0

WORT=0

while read WORT && [ -n "$WORT" ]
do
     echo $WORT|grep a>/dev/null || echo $WORT|grep B>/dev/null || let i=$i+1
done

echo $i

The read loop will stop with an empty input.

Last edited by rdrtx1; 02-01-2018 at 06:32 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

any explanation for thsi shell script behaviour

hello whats the difference between excuting a shell script as a)sh myscript.sh b). ./myscript.sh i noticed that my shell script works fine when i run it as . ./myscript .sh but fails when i run it as sh myscript.sh could anybody explain why. the shell script is very simple ... (9 Replies)
Discussion started by: xiamin
9 Replies

2. Shell Programming and Scripting

Script explanation

I have the following script awk '$1 ~ /^*+/ { s += $NF; m++ } END { print NR, m, s } and I use it to get results from the following file A4792 4 COMP9021 5 K9 7 ABC 8 924 1 R2D2 3 (8 Replies)
Discussion started by: sickboy
8 Replies

3. Shell Programming and Scripting

Explanation of running this script

I have a script that has defined a log file like this. The name of the script is verify.sh Inside the script there is some thing like this. LOG=/usr/verify TDATE=`date "+%m%d%y"$$` LOGFILE=$LOG.$TDATE. and inside the script it has been written as echo "This is to verify" | tee -a... (2 Replies)
Discussion started by: sendhilmani
2 Replies

4. Shell Programming and Scripting

Need explanation of script

Hi All, Can anybody explain what this script is doing? #!/bin/sh who | cut -d " " -f1 | sort -u > userlist1 while true ; do sleep 60 who | cut -d" " -f1 | sort -u >userlist2 for username in `cat userlist1` ; do if ! grep "^$username$" userlist2 > /dev/null ; then echo... (0 Replies)
Discussion started by: vishalpatel03
0 Replies

5. Shell Programming and Scripting

explanation for a script

Guys, was wondering what the meaning of the below bit is ? awk -F ' ' '{print $1 " " $2 ;}' $TEMPFILE | (rm -f $TEMPFILE; sed 's/$/ '"$box"'/g' > $TEMPFILE) Can anyone explain this in detail? what is the significance of rm -f $TEMPFILE here? What all IO/buffering happens here ?How the... (0 Replies)
Discussion started by: hashin_p
0 Replies

6. Shell Programming and Scripting

Shell Script Explanation

Hello, I have seen this script on this site. I understand most of it. However I am a bit stuck on the part in red. It appears to be expanding for file in *.zip do zipdir=${file%.*} mkdir $zipdir || echo "unable to create $zipdir" cp $file $zipdir || echo "unable to copy $file"... (3 Replies)
Discussion started by: jaysunn
3 Replies

7. Shell Programming and Scripting

Script explanation

#script fileused=test.txt hostname=test.dis.com ftp $hostname <<-! > $fileused.err 2>&1 put file.txt /usr/text.txt bye ! kindly the above script the one marked as Bold and underlined as the above i am declaring the new variable as filename ,But when i used i had used as $fileused.err... (1 Reply)
Discussion started by: rajar_r
1 Replies

8. Shell Programming and Scripting

need an explanation on this script...

The following script will create a directory in a directory and will go on as many times as the number you will give in. I am trying to find out how it works ... can someone please help me with that? #!/bin/sh #create a variable and set it to 1 n=1 #start a loop as... (3 Replies)
Discussion started by: I-1
3 Replies

9. Solaris

Explanation of script

Hello Guys, can someone help explain the script below for me? I will really appreciate it. vi db_script #!/bin/sh echo .cron job run on.`date`> cronjob.txt df -h >> cronjob.txt echo welcome to home (2 Replies)
Discussion started by: cjashu
2 Replies

10. Shell Programming and Scripting

What does this shell script do? Need in depth explanation please

Hi My friend wrote this particular script and won't tell me what it does, and when I run it I don't understand it. What does the entire script do with specifics please. Thanks Bob #!/bin/bash current=0 while ; do if ; then echo ${current} current=$((${current}+1)) fi done (1 Reply)
Discussion started by: shadowknight777
1 Replies
KPROF(3)						     Library Functions Manual							  KPROF(3)

NAME
kprof - kernel profiling SYNOPSIS
bind -a #T /dev /dev/kpctl /dev/kpdata DESCRIPTION
The kprof device provides simple profiling data for the operating system kernel. The data accumulates by recording the program counter of the kernel at each `tick' of the system clock. The file kpdata holds the accumulated counts as 4-byte integers in big-endian byte order. The size of the file depends on the size of ker- nel text. The first count holds the total number of clock ticks during profiling; the second the number of ticks that occurred while the kernel was running. The rest each hold the number of ticks the kernel program counter was within the corresponding 8-byte range of kernel text, starting from the base of kernel text. The file kpctl controls profiling. Writing the string start to kpctl begins profiling; stop terminates it. The message startclr restarts profiling after zeroing the array of counts. The program kprof (see prof(1)) formats the data for presentation. EXAMPLE
The following rc(1) script runs a test program while profiling the kernel and reports the results. bind -a '#T' /dev echo start > /dev/kpctl runtest echo stop > /dev/kpctl kprof /mips/9power /dev/kpdata SOURCE
/sys/src/9/port/devkprof.c SEE ALSO
prof(1) KPROF(3)
All times are GMT -4. The time now is 04:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy