LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-09-2004, 09:16 PM   #1
Echo Kilo
Member
 
Registered: Jul 2004
Distribution: Ubuntu - Debian Based
Posts: 242

Rep: Reputation: 30
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

Oops, I just realized this is in the wrong category forum.

Last edited by Echo Kilo; 11-09-2004 at 09:57 PM.
 
Old 11-09-2004, 09:30 PM   #2
ranger_nemo
Senior Member
 
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
You can do integer math inside a $(( )), or with a let statement. The following three statements should all make $x = 2...
x=$((1+1))
let x=1+1
let x='1 + 1'
Code:
#!/bin/bash
let low_val=0
let high_val=20
while [ $low_val -le $high_val ]
do
  echo -n $low_val " "
  low_val=$(($low_val + 1))
done
I've not see the count line before. A better way to do it might be a while loop as above.
 
Old 11-09-2004, 10:01 PM   #3
Echo Kilo
Member
 
Registered: Jul 2004
Distribution: Ubuntu - Debian Based
Posts: 242

Original Poster
Rep: Reputation: 30
But what do they do? This is a question we had in class today and no one knew.

Here are the questions:


A. What do these two scripts do?

B. Do these scripts interact? If so, how?

C. What change(s), if any, would increase portability?

D. What change(s), if any, would make them easier to understand?

E. Why are these two scripts separate? Why not combine them into one?
 
Old 11-10-2004, 01:06 AM   #4
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
2 things:

This is clearly not a success story - if anything, it belongs in Programming. Moved.

The second is a quote from the Rules: " Do not expect LQ members to do your homework - you will learn much more by doing it yourself."
 
Old 11-10-2004, 03:15 PM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: Any idea what these scripts do?

Quote:
Originally posted by Echo Kilo
I coudn't get the count command to work.
"count" should be "seq".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VPN: Debian Scripts -> Mandriva 2006 Scripts Undefined Mandriva 0 11-30-2005 12:10 PM
Any idea what these scripts do? Echo Kilo Linux - General 6 11-14-2004 10:37 PM
Need help running scripts from scripts sdouble Linux - Newbie 3 05-31-2004 12:56 PM
any idea... kazuni Linux - Newbie 4 05-23-2003 03:17 PM
No idea what to do. Tayste_2000 Linux - General 3 06-18-2002 10:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration