both sides execution of command

Tags
shell scripts

 
Thread Tools Search this Thread
# 1  
Old 05-12-2011
both sides execution of command

Hi,

i am struggling with a chunk of code.

Code:
    for ((i=1; i<=3; i++));do
        one-$i ="/tmp/one.$RANDOM"
    done

How to execute the above code.
In both sides(LHS and RHS), i am executing commands.
it is not allowing to execute.

can you please give the idea.

It should be very appreciable, if i get an example.

Thanks.

Last edited by pludi; 05-12-2011 at 05:19 AM..
# 2  
Old 05-12-2011
what are you exactly trying here ?

Please help us with some explanation.
# 3  
Old 05-12-2011
I like to get the output as
one-1="/tmp/one.22345"
one-2="/tmp/one.22346"

I mean to say like, I want to intialize two variables, one-1 one-2 with respective values.
# 4  
Old 05-12-2011
one-$i ="/tmp/one.$RANDOM" Won't work
  1. use eval
  2. no space around '='
Code:
eval "one-$i=/tmp/one.$RANDOM"

# 5  
Old 05-12-2011
Quote:
Originally Posted by frans
one-$i ="/tmp/one.$RANDOM" Won't work
  1. use eval
  2. no space around '='
Code:
eval "one-$i=/tmp/one.$RANDOM"

Code:
sh-3.00# for ((i=1; i<=3; i++));do echo $(eval "one-$i=one.$RANDOM"); done
sh: one-1=one.13352: command not found

sh: one-2=one.14261: command not found

sh: one-3=one.15170: command not found

sh-3.00#

it is saying like command not found..
but it is not command
# 6  
Old 05-12-2011
Code:
$ for ((i=1; i<=3; i++));do eval "one_$i=one.$RANDOM" ; done
$ echo $one_1
one.21586
$ echo $one_2
one.22755
$ echo $one_3
one.17778

This worked for me. can you try this.

---------- Post updated at 04:05 PM ---------- Previous update was at 04:02 PM ----------

I just changed the '-' to '_', it is not interpreting the latter as a command. Not sure why.

I think bash variables shouldn't contain special chars other than '_'.

Because it neither worked with '.'
# 7  
Old 05-12-2011
Quote:
Originally Posted by kumaran_5555
(...)
I just changed the '-' to '_', it is not interpreting the latter as a command. Not sure why.
I think bash variables shouldn't contain special chars other than '_'.
Right. I should have seen that !

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Execution of command at command prompt babyPen1985 UNIX for Dummies Questions & Answers 4 08-27-2014 04:38 PM
Parallel Execution of Command jerome_rajan UNIX for Advanced & Expert Users 2 01-16-2014 05:31 AM
Command execution from other directory munna_dude Shell Programming and Scripting 1 07-10-2013 04:14 AM
Multiple command execution inside awk command during xml parsing vivek d r Shell Programming and Scripting 2 02-11-2013 01:56 AM
Want to terminate command execution when string found in the command output Hanumant.madane Shell Programming and Scripting 19 10-21-2012 11:25 AM
HMC updates managed system firmware on both T and P sides ? vilius AIX 0 09-19-2011 01:01 AM
get the total execution of command shankr3 Solaris 3 01-31-2011 09:33 AM
Command execution in grep kkhan00 UNIX for Dummies Questions & Answers 2 10-05-2010 10:23 PM
Code for execution command by command sriki32 Shell Programming and Scripting 6 09-22-2010 02:45 PM
command execution alert dddkiran UNIX for Advanced & Expert Users 8 03-25-2010 09:45 AM
Remote command execution uunniixx Shell Programming and Scripting 4 04-03-2009 12:26 AM
slow command execution? BandGap Shell Programming and Scripting 2 02-04-2009 10:32 AM
command execution time hashin_p Shell Programming and Scripting 5 07-06-2008 08:28 PM
command execution ?? zedex UNIX for Advanced & Expert Users 1 11-06-2007 05:26 PM