LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Any idea what these scripts do? (https://www.linuxquestions.org/questions/linux-general-1/any-idea-what-these-scripts-do-253060/)

Echo Kilo 11-09-2004 09:57 PM

Any idea what these scripts do?
 
Any idea what these scripts do? I coudn't get the count command to work. :(


#!/bin/bash
string="The quick brown fox jumped over the lazy dog"
for i in `count 5 20`
do
echo $string | cut –c $i
done



#!/bin/bash
low_val=$1;high_val=$2
while [ $low_val -le $high_val ]
do
echo -n $low_val " "
low_val=`expr $low_val + 1`
done

Echo Kilo 11-09-2004 10:02 PM

This is a question we had in class today and no one knew.

Echo Kilo 11-10-2004 12:44 AM

Anyone?

homey 11-10-2004 12:13 PM

They are made for walking up a ladder from the fist step ( val_low ) to the top ( val_high ) and printing the results.

This is the ladder for the first part
low_val=`expr $low_val + 1`

This is the ladder for the second part
for((i=5; i<=$high_val; i++))

You can't use $low_val here as it is actually a much higher value than you might expect. You can show that by putting a couple of echos statements in the code ....
echo $low_val
echo $high_val
for((i=5; i<=$high_val; i++))


Code:

#!/bin/bash

low_val=5;high_val=20
while [ $low_val -le $high_val ]
do
echo -n $low_val " "
low_val=`expr $low_val + 1`
done

echo ""
string="The quick brown fox jumped over the lazy dog"
for((i=5; i<=$high_val; i++))
do
echo $string |cut -c $i
done


J.W. 11-10-2004 02:07 PM

Quote:

Originally posted by Echo Kilo
This is a question we had in class today and no one knew.
Per the LQ Rules "Do not expect LQ members to do your homework - you will learn much more by doing it yourself." -- J.W.

randyriver10 11-12-2004 08:51 AM

Or don't make two identical posts in two different forums!

Echo Kilo 11-14-2004 10:37 PM

It wasn't homework, just a question that was posed and I apologize for any headaches.


All times are GMT -5. The time now is 10:00 PM.