The first lane initializie the variable i with the value of 0.
The loop line has 3 different options because of ||. The only option I understand
is that i gets +1 everytime if the other two options dont apply.
Last line just gives out the value i after the while loop is done.
I dont understand this line "echo $WORT|grep a>/dev/null || echo$WORT|grep B>dev/null "
Last edited by Don Cragun; 02-01-2018 at 06:37 PM..
Reason: Add ICODE tags.
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:
The read loop will stop with an empty input.
I still dont actually understand it. In my solution I have like 15 files
Abbe, Ananas, Apfel, Apfelsine, Asterix, Backen, Berg, Burg, Hacken, Halle,
Huepfen, Obelix, Schuber, Werbung, Barbier
to use this script it would be ls | /home/notroot/scripts/myscript.sh
Can you tell me why would it count like 15 times for a or 10 tims for B?
Moderator's Comments:
Please use CODE tags (not ICODE tags) when displaying full-line and multi-line code segments, sample input, and sample output. Use ICODE tags when displaying partial-line code segments, sample input, and sample output.
Last edited by Don Cragun; 02-01-2018 at 06:46 PM..
Reason: Change ICODE tags to CODE tags; add ICODE tags.
With the explanation from earlier I get that grep a>/dev/null does count if the file contains the letter a right?
Is the reason for 15 times because its the first instruction if yes then I guess I understand this part. But what is with B?
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)
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)
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)
#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)
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)
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)
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)
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)
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)
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)