Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
munna_dude's Unix or Linux Image
munna_dude munna_dude is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 19 July 2013, 3:37 AM EDT
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
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..
Sponsored Links
    #2  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
kumaran_5555's Unix or Linux Image
kumaran_5555 kumaran_5555 is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 15 March 2015, 2:47 AM EDT
Location: India
Posts: 353
Thanks: 9
Thanked 50 Times in 49 Posts
what are you exactly trying here ?

Please help us with some explanation.
Sponsored Links
    #3  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
munna_dude's Unix or Linux Image
munna_dude munna_dude is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 19 July 2013, 3:37 AM EDT
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
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 Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
frans's Unix or Linux Image
frans frans is offline Forum Advisor  
Registered User
 
Join Date: Oct 2009
Last Activity: 1 February 2016, 9:47 AM EST
Location: France
Posts: 839
Thanks: 4
Thanked 54 Times in 53 Posts
one-$i ="/tmp/one.$RANDOM" Won't work
  1. use eval
  2. no space around '='


Code:
eval "one-$i=/tmp/one.$RANDOM"

Sponsored Links
    #5  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
munna_dude's Unix or Linux Image
munna_dude munna_dude is offline
Registered User
 
Join Date: Jan 2007
Last Activity: 19 July 2013, 3:37 AM EDT
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by frans View Post
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
Sponsored Links
    #6  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
kumaran_5555's Unix or Linux Image
kumaran_5555 kumaran_5555 is offline
Registered User
 
Join Date: Jul 2008
Last Activity: 15 March 2015, 2:47 AM EDT
Location: India
Posts: 353
Thanks: 9
Thanked 50 Times in 49 Posts


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 '.'
Sponsored Links
    #7  
Old Unix and Linux 05-12-2011   -   Original Discussion by munna_dude
frans's Unix or Linux Image
frans frans is offline Forum Advisor  
Registered User
 
Join Date: Oct 2009
Last Activity: 1 February 2016, 9:47 AM EST
Location: France
Posts: 839
Thanks: 4
Thanked 54 Times in 53 Posts
Quote:
Originally Posted by kumaran_5555 View Post
(...)
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 !
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Command execution in grep kkhan00 UNIX for Dummies Questions & Answers 2 10-05-2010 09:23 PM
Code for execution command by command sriki32 Shell Programming and Scripting 6 09-22-2010 01:45 PM
tar command loop during execution Jocker UNIX for Advanced & Expert Users 15 07-08-2009 08:13 AM
command execution ?? zedex UNIX for Advanced & Expert Users 1 11-06-2007 04:26 PM



All times are GMT -4. The time now is 11:40 AM.