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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-02-2004, 02:11 AM
|
#1
|
|
Member
Registered: Jan 2004
Location: California
Distribution: Slackware 10.1
Posts: 190
Rep:
|
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?
|
|
|
|
06-02-2004, 02:55 AM
|
#2
|
|
Member
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106
Rep:
|
Hi,
change
$num = $num + 1
to
let num=$num+1
and it should work.
|
|
|
|
06-02-2004, 03:21 AM
|
#3
|
|
LQ Newbie
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16
Rep:
|
or: num=`expr $num + 1`
|
|
|
|
06-02-2004, 09:30 AM
|
#4
|
|
Member
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185
Rep:
|
while we're seeing how many different ways there are to skin a cat, here's another:
((num=num+1))
|
|
|
|
06-02-2004, 09:51 AM
|
#5
|
|
LQ Newbie
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16
Rep:
|
mfeat:
Can you explain this expression ----> ((num=num+1))
I cannot understand the syntax.
thanks
|
|
|
|
06-02-2004, 10:39 AM
|
#6
|
|
Moderator
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris10, Solaris 11, Mint, OL
Posts: 9,324
|
a longer way to express: ((num++)) ...
|
|
|
|
06-02-2004, 01:16 PM
|
#7
|
|
Member
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185
Rep:
|
"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
|
|
|
|
06-02-2004, 01:20 PM
|
#8
|
|
Member
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185
Rep:
|
"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".
|
|
|
|
06-02-2004, 08:42 PM
|
#9
|
|
Member
Registered: Feb 2003
Location: Wichita, KS
Distribution: Heavily modified Redhat
Posts: 194
Rep:
|
How about
Code:
for num in `seq 1 8`; do
tar -xzvf X11R6.7.0-src$num.tar.gz
done
|
|
|
|
06-02-2004, 11:47 PM
|
#10
|
|
LQ Newbie
Registered: May 2004
Location: Beijing, China
Distribution: Debian
Posts: 16
Rep:
|
 everyone is perfect
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:11 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|