LinuxQuestions.org
Visit Jeremy's Blog.
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, 02: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, 02: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, 03: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, 09: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, 09: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, 10:39 AM   #6
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Ubuntu/WSL
Posts: 9,788

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
a longer way to express: ((num++)) ...
 
Old 06-02-2004, 01: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, 01: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, 08: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-02-2004, 11:47 PM   #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 09:13 PM
Simple shell script mikz Linux - General 1 02-24-2005 07:18 AM
a simple shell script Warchief Programming 1 07-31-2003 05:01 AM
Very Simple Shell Script cli_man Linux - Software 5 04-24-2003 10:14 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM

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

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

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