Home Man
Search
Today's Posts
Register

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

both sides execution of command

Tags
shell scripts

Login to Reply

 
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 04: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 !
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Execution of command at command prompt babyPen1985 UNIX for Dummies Questions & Answers 4 08-27-2014 03:38 PM
Command execution from other directory munna_dude Shell Programming and Scripting 1 07-10-2013 03:14 AM
Multiple command execution inside awk command during xml parsing vivek d r Shell Programming and Scripting 2 02-11-2013 12:56 AM
Want to terminate command execution when string found in the command output Hanumant.madane Shell Programming and Scripting 19 10-21-2012 10:25 AM
HMC updates managed system firmware on both T and P sides ? vilius AIX 0 09-19-2011 12:01 AM
Code for execution command by command sriki32 Shell Programming and Scripting 6 09-22-2010 01:45 PM
Execution problems using awk command. satishpv_2002 Shell Programming and Scripting 4 08-16-2009 10:17 PM
command execution time hashin_p Shell Programming and Scripting 5 07-06-2008 07:28 PM
command execution ?? zedex UNIX for Advanced & Expert Users 1 11-06-2007 04:26 PM


All times are GMT -4. The time now is 02:52 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password