Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-10-2006, 04:26 PM   #1
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?


string="The quick silver fox jumped over the lazy dog"
for i in `count 5 20`
echo $string | cut c $i


while [ $low_val -le $high_val ]
echo -n $low_val " "
low_val=`expr $low_val + 1`

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, 04:41 PM   #2
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:
Or the bookmark section, which has an overwhelming amount of info
Old 05-10-2006, 04:50 PM   #3
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, 04:16 AM   #4
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:
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:
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


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

All times are GMT -5. The time now is 04:01 AM.

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