Setting the Results of a Command to a Variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Setting the Results of a Command to a Variable
# 1  
Old 02-29-2008
Error Setting the Results of a Command to a Variable

Hi,

Hi, I run the command:

hostname to get the host back from the server: db201


Now, I need to take that result and set it to a variable. Can anyone help me with this?? I need to be able to use the same script on multiple servers so I do not want to hardcode the hostname result into the variable.

Can anyone please help?!


Thanks in advance!
# 2  
Old 02-29-2008
Code:
MYHOST=`hostname`
echo "$MYHOST"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to add a variable for the results from the formula of one variable and results of another var

Good morning all, This is the file name in question OD_Orders_2019-02-19.csv I am trying to create a bash script to read into files with yesterdays date on the file name while retaining the rest of the files name. I would like for $y to equal, the name of the file with a formula output with... (2 Replies)
Discussion started by: Ibrahim A
2 Replies

2. Shell Programming and Scripting

awk - saving results of external script to variable.

So, I've been playing with speeding up some analysis we do by using multiple threads of awk (actually, mawk, but code-compatible as far as I use it) on multiple CPU cores. So, I have a big data file and I have several copies of exactly the same processor script, written in mawk. I also have a... (8 Replies)
Discussion started by: treesloth
8 Replies

3. Programming

Results Of A Variable Into An Array Using C Language

Can C add its results into an array like bash? For example using bash: cat /etc/passwd **truncated for space ** gdm:x:109:118:Gnome Display Manager:/var/lib/gdm:/bin/false mysql:x:110:122:MySQL Server,,,:/nonexistent:/bin/false statd:x:111:65534::/var/lib/nfs:/bin/false... (5 Replies)
Discussion started by: metallica1973
5 Replies

4. UNIX for Advanced & Expert Users

Place the results of a CUT command into a variable

I am being passed a file in UNIX, ie: variable.txt I need to extract the first part of the file content, up to the period, content ie: common_dir.second_output cut -d'.' -f1 /content/stores/variable.txt I then need to utilize the results to create a variable ($1), and test on that... (4 Replies)
Discussion started by: talonbow
4 Replies

5. Shell Programming and Scripting

Adding grep'd results in a variable

Here is one I am baffled with; I have not used unix for a while and now that I am back it has been fun remembering and I have enjoyed it, for the most past. this is in ksh. I need to search in a file for the line with X1 and cut columns 20-25, put them into a variable, added them (dollar... (3 Replies)
Discussion started by: CougarMutt
3 Replies

6. UNIX for Dummies Questions & Answers

how to - redirect query results to a variable

How can I send the results of a query to a unix variable. I basically want to run a query then do some logic on the results. Trying to redirect the result into a variable I define in the script. select count(*) as counter from table - nut to redirect the "count" returned from the query... (2 Replies)
Discussion started by: rstone
2 Replies

7. UNIX for Dummies Questions & Answers

putting grep -c results number in a variable

I want to display "no results found" if a grep search of a name that the user inputs is not found anywhere in a certain file, Right now I have this, but doesn't seem to work. Im not sure what to change. read name results=grep -c $name file if ; then echo "No results found." exit... (1 Reply)
Discussion started by: busdude
1 Replies

8. Shell Programming and Scripting

Grep results to store in a shell variable

I have the results of a grep with -n store in a shell variable ie VAR=`grep -n -e 'PATTERN' file` How ever I am missing the line breaks in the variable , How do I store the resualts of grep with many lines in to a variables. I want the varable should be the sawmway as we do the grep grep... (3 Replies)
Discussion started by: jojan
3 Replies

9. Shell Programming and Scripting

store awk results in a variable

I try to get the month (of last save) and the filename into a variable, is this possible ? something like this : for month in `ls -la | awk '{print $6}'` do if ] then a=filename of the matching file cp $a /Sep fi thanks, Steffen (1 Reply)
Discussion started by: forever_49ers
1 Replies

10. Windows & DOS: Issues & Discussions

Setting a variable to result of FIND command

I am working on a batch script where a filter is placed on a directory, and the files that come out of that filter have to be copied into another directory. More specifically, I am trying to set the results of a FIND command to a variable, so that I may access this variable / file later. The... (2 Replies)
Discussion started by: JP Favara
2 Replies
Login or Register to Ask a Question