LinuxQuestions.org
Register a domain and help support LQ
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 05-10-2006, 03:26 PM   #1
kcals
LQ Newbie
 
Registered: Apr 2006
Distribution: Slackware 2.6.13
Posts: 19

Rep: Reputation: 0
Noobs question


Hello eveyone.
I have two scripts that interact.First script call the second to change the string from a horizontal line to a vertical.
Can you please explain step by step how this happens?

1.

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

2.

#!/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


Thank you.

PS Is there any way to combine those two int one script?
Will that be a good idea or I should leave em as they are?
 
Old 05-10-2006, 03:41 PM   #2
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
For such small scripts i would combine the two into one.
It also depends on whether you'd want to re-use one of them seperately.
Read some more over here on bash/script/functions: http://linuxcommand.org/wss0070.php
Or the bookmark section, which has an overwhelming amount of info
http://bookmarks.linuxquestions.org/linux?like=bash
 
Old 05-10-2006, 03:50 PM   #3
kcals
LQ Newbie
 
Registered: Apr 2006
Distribution: Slackware 2.6.13
Posts: 19

Original Poster
Rep: Reputation: 0
Cool those are nice links I will visit em often.
Thx for the answer too.
But wat about you explain how the scripts work line by line.
I will appreciate it.
 
Old 05-11-2006, 03:16 AM   #4
osvaldomarques
Member
 
Registered: Jul 2004
Location: Rio de Janeiro - Brazil
Distribution: Conectiva 10 - Conectiva 8 - Slackware 9 - starting with LFS
Posts: 519

Rep: Reputation: 34
Hi kcals,

As you didn't named the script files, I presume the second script name is "count".
In the third line of the first script you call it passing 2 arguments, "5" and "20".
These arguments will initialize the variables low_val and high_val. Then it enters in a "while loop" checking for low_val less or equal to high_val. While this condition is TRUE, it echoes the content of low_val and a space without advance to the next line. Then it increments the value of the low_val using the eval command. When the loop finishes, it returns the line containing the sequence "5 6 7 ... 20" to the first script.
This result replaces the call text in the line which invoked the second script because it's using command substitution, represented by the "back quotes". So this line can be read as:
Code:
for i in 5 6 7 8 9 ... 20
The "for" command will replace the contents of "i" by each of thes values at each iteration.
The commands into the loop will display the string, cuting it with the number of characters specified by the parameter, which is the content of the variable "i".

So, we will see:
Code:
The q
The qu
The qui
The quic
The quick
The quick 
The quick s
The quick si
The quick sil
The quick silv
The quick silve
The quick silver
The quick silver 
The quick silver f
The quick silver fo
The quick silver fox
 
  


Reply

Tags
bash, script


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
noobs level Thulemanden Linux - Newbie 1 10-21-2005 12:56 PM
Prayer for noobs floppywhopper General 20 09-30-2005 05:38 AM
Noobs java question on applets probably easy...sorry in advance vdogvictor Programming 2 03-16-2004 11:58 AM
Distro For A Noobs HyBriDJoKeR Linux - Newbie 31 02-05-2004 02:28 PM
--geometry for noobs mcd Linux - Newbie 4 08-29-2003 10:48 PM


All times are GMT -5. The time now is 07:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration