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 06-02-2004, 03:11 AM   #1
sharpie
Member
 
Registered: Jan 2004
Location: California
Distribution: Slackware 10.1
Posts: 190

Rep: Reputation: 30
simple shell script


I have 8 tar.gz files that all have the same name, apart from 1 number, obviously going from 1 to 8. Here is the shell script I created, the first tar.gz filename is X11R6.7.0-src1.tar.gz:

Code:
#!/bin/bash

num=1
while [ $num -lt 8 ]; do
	tar -xzvf X11R6.7.0-src$num.tar.gz
	$num = $num + 1
done
It starts to extract and uncompress the 1st one, but never gets to the second one - it just keeps looping on the first one. It seems as though it's ignoring the $num = $num + 1 statement and is just looping the same tar command. What am I doing wrong?
 
Old 06-02-2004, 03:55 AM   #2
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
Hi,
change
$num = $num + 1
to
let num=$num+1
and it should work.
 
Old 06-02-2004, 04:21 AM   #3
seeLnd
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16

Rep: Reputation: 0
or: num=`expr $num + 1`
 
Old 06-02-2004, 10:30 AM   #4
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
while we're seeing how many different ways there are to skin a cat, here's another:

((num=num+1))
 
Old 06-02-2004, 10:51 AM   #5
seeLnd
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16

Rep: Reputation: 0
mfeat:

Can you explain this expression ----> ((num=num+1))
I cannot understand the syntax.

thanks
 
Old 06-02-2004, 11:39 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,523

Rep: Reputation: 365Reputation: 365Reputation: 365Reputation: 365
a longer way to express: ((num++)) ...
 
Old 06-02-2004, 02:16 PM   #7
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
"a longer way to express: ((num++))"

cool! i learn something new everyday on this board! i think that sytax is as terse as it gets
 
Old 06-02-2004, 02:20 PM   #8
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
"Can you explain this expression ----> ((num=num+1))
I cannot understand the syntax."

seeLND:

from the bash man page:

((expression))
The expression is evaluated according to the rules described
below under ARITHMETIC EVALUATION. If the value of the expres-
sion is non-zero, the return status is 0; otherwise the return
status is 1. This is exactly equivalent to let "expression".
 
Old 06-02-2004, 09:42 PM   #9
jspenguin
Member
 
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194

Rep: Reputation: 30
How about
Code:
for num in `seq 1 8`; do
	tar -xzvf X11R6.7.0-src$num.tar.gz
done
 
Old 06-03-2004, 12:47 AM   #10
seeLnd
LQ Newbie
 
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16

Rep: Reputation: 0
everyone is perfect
 
  


Reply


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
Simple Shell Script Help Kristijan Programming 3 06-13-2005 10:13 PM
Simple shell script mikz Linux - General 1 02-24-2005 08:18 AM
a simple shell script Warchief Programming 1 07-31-2003 06:01 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 11:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


All times are GMT -5. The time now is 01:32 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration