473,899 Members | 4,542 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can we assign a variable for a commad

31 New Member
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 4239
horace1
1,510 Recognized Expert Top Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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 Recognized Expert Contributor
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 Recognized Expert Top Contributor
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
8401
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 logindisabled=FALSE Instead of parsing this text and assigning the values, I was wondering
25
4366
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 them, but the assign operator is always forcing them to "type cast" or coerce the result when they do a simple assign for the purpose of setting the value of a variable. Borrowing an example from this newgroup, the second assignment below ereases...
5
2977
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 variables (Microsoft OLE DB privider for V.FoxPro: Too many Variables).
2
8334
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. any ideas??
4
12594
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)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
4
4250
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 similar to add a new control to a form using the controls collection: Private Sub CommandCreateInstance_Click()
6
2288
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 = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") ------code ------- Dim field As String = "Q"
2
3162
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 luck assigning the results. I have the need to assign the primary key of a table, which is an auto number data type) therefore a numeric value. My select is very basic for I am just looking for the primary key where two options are met. "SELECT...
9
2370
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 "using { Pen mypen = new Pen(Color.Black, 1)) {}), which I think makes a difference: I find the following assignment does not work: //myPenTest instantiated in the normal constructor, as was baseline,
0
9843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10863
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9666
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7201
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4720
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4300
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3317
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.