473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Can we assign a variable for a commad

Hi,

Can i assign a variable..Here is my sample code:
$a = who grep $LOGNAME
$b = pwd
Is this right or wrong.
Mar 1 '07 #1
7 4227
horace1
1,510 Expert 1GB
Hi,

Can i assign a variable..Here is my sample code:
$a = who grep $LOGNAME
$b = pwd
Is this right or wrong.
try
Expand|Select|Wrap|Line Numbers
  1. a=ls
  2. b=pwd
  3. $a
  4. $b
  5.  
Mar 2 '07 #2
ghostdog74
511 Expert 256MB
Hi,

Can i assign a variable..Here is my sample code:
$a = who grep $LOGNAME
$b = pwd
Is this right or wrong.
not quite. use backticks
Expand|Select|Wrap|Line Numbers
  1. $a = `who |grep $LOGNAME`
  2. $b = `pwd`
  3.  
Mar 2 '07 #3
horace1
1,510 Expert 1GB
not quite. use backticks
Expand|Select|Wrap|Line Numbers
  1. $a = `who |grep $LOGNAME`
  2. $b = `pwd`
  3.  
which shell are you using?

mine
Expand|Select|Wrap|Line Numbers
  1. a=ls
  2. b=pwd
  3. $a
  4. $b
  5.  
works using bash but not csh
Mar 3 '07 #4
ghostdog74
511 Expert 256MB
which shell are you using?

mine
Expand|Select|Wrap|Line Numbers
  1. a=ls
  2. b=pwd
  3. $a
  4. $b
  5.  
works using bash but not csh
bash. and should be like this instead
Expand|Select|Wrap|Line Numbers
  1. a=`who |grep $LOGNAME`
  2. b=`pwd`
  3.  
Mar 3 '07 #5
horace1
1,510 Expert 1GB
on my linux PC
Expand|Select|Wrap|Line Numbers
  1. a=ls
  2. b=pwd
  3. $a
  4. $b
  5.  
works with bash and
Expand|Select|Wrap|Line Numbers
  1. set a=ls
  2. set b=pwd
  3. $a
  4. $b
  5.  
works with csh
Mar 3 '07 #6
ghostdog74
511 Expert 256MB
on my linux PC
Expand|Select|Wrap|Line Numbers
  1. a=ls
  2. b=pwd
  3. $a
  4. $b
  5.  
I had a different interpretation of what the OP needs.
I assume he wants to store the results of the who|grep and 'pwd' command to variables 'a' and 'b'. so if that's the case, the above is not correct.
But if OP just wants to store the word "ls" in 'a' and the word "pwd" in b, then its correct.
Mar 3 '07 #7
horace1
1,510 Expert 1GB
I had a different interpretation of what the OP needs.
I assume he wants to store the results of the who|grep and 'pwd' command to variables 'a' and 'b'. so if that's the case, the above is not correct.
But if OP just wants to store the word "ls" in 'a' and the word "pwd" in b, then its correct.
I think that vasu1308 needs to tell us exactly what is required?
Mar 3 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Mike | last post by:
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z...
25
by: Rim | last post by:
Hi, I have been thinking about how to overload the assign operation '='. In many cases, I wanted to provide users of my packages a natural interface to the extended built-in types I created for...
5
by: flemming eriksen | last post by:
Dear NG. IIS5 (and II6) , ASP 3.0.; W2k, WS03. A websolution has a login-page, transaction page (just reading data), and logout-page Under heavy load I get in the IIS-Log : Too many...
2
by: Matt | last post by:
If I assign VBScript server side variable a to javascript variable x, it is fine. <% Dim a, b a = 10 %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error....
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
4
by: Andres | last post by:
Hi all, I have the problem to assign a variable of type object to a specific class at runtime. I want to use a string variable that specify the class a want to set this object. Is something...
6
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text =...
2
by: Birky | last post by:
Assign the output of a select to a variable? I am unable to find a way to assign the results of an SQL statement to a variable. I know how to assign the SQL statement to a variable but again no...
9
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.