LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 01-30-2010, 05:50 AM   #1
CrossoverPsycho
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Rep: Reputation: 0
bash question about variables


Heyho,

I'm trying to write a .sh script that allows me to run multiple other .sh scripts at once.

My problem occurs within a Variable:

I have set

S1 to S7 to be the name of the .sh


A="7"
B="S$A"
C="$S$A" <- and this is where my problem is

I want C to be the content of S7 till S1 but if I run this line it will of course look for the content of S and link it with the content of A.

How can I correct this?

Thank you in advance.

Cross


Edit:

WHERE="/home/X/Y/"
SH=".sh";

A="7";
B="S$A";
C="$B";

cd $WHERE;

function start
{
if [ $B != "S0" ]; then
cd $WHERE;
./"$C$SH start";
echo "$C has been started";
A=$[$A-1];
B="S$A";
C="$B";
start;
else
screen -list;
exit;
fi
}

start;
exit;

Last edited by CrossoverPsycho; 01-30-2010 at 06:07 AM.
 
Old 01-30-2010, 06:02 AM   #2
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Quote:
Originally Posted by CrossoverPsycho View Post
Heyho,

I'm trying to write a .sh script that allows me to run multiple other .sh scripts at once.

My problem occurs within a Variable:

I have set

S1 to S7 to be the name of the .sh


A="7"
B="S$A"
C="$S$A" <- and this is where my problem is

I want C to be the content of S7 till S1 but if I run this line it will of course look for the content of S and link it with the content of A.

How can I correct this?

Thank you in advance.

Cross
Why can't you assign c="S1" directly?
 
Old 01-30-2010, 06:06 AM   #3
CrossoverPsycho
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Because I'm using A=$[$A-1] in my code and want C to get the names from S7 to S1.

I'll edit the code into my first post ^^
 
Old 01-30-2010, 06:13 AM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Use arrays:

http://tldp.org/LDP/abs/html/arrays.html
 
1 members found this post helpful.
Old 01-30-2010, 06:42 AM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
The syntax you want to use is simply no possible. Usng arrays might be an option as suggested by macemoneta.

Check the link in my signature.

jlinkels
 
Old 01-30-2010, 07:51 AM   #6
CrossoverPsycho
LQ Newbie
 
Registered: Jan 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you it works perfectly fine now ^^
 
Old 01-30-2010, 08:11 AM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Moved to Programming
 
  


Reply



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
Question about variables in BASH scripts gimpy530 Linux - General 5 11-19-2009 10:02 PM
bash programming question - hand over variables to another script ppr:kut Linux - General 5 02-09-2008 10:00 AM
bash/ksh variables question tpe Programming 2 08-11-2005 09:39 AM
bash script - variables & arrays question rblampain Linux - Software 4 09-25-2004 09:57 AM
BASH variables evaluation question. Thetargos Programming 11 08-11-2003 04:11 AM

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

All times are GMT -5. The time now is 08:16 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