storing a value from another file as a variable[solved]


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting storing a value from another file as a variable[solved]
# 1  
Old 05-21-2012
storing a value from another file as a variable[solved]

Hi all, im having snags creating a variable which uses commands like cut and grep. In the instance below im simply trying to take a value from another file and assign it to a variable. When i do this it only prints the $a rather than the actual value. I know its simple but does anyone have any ideas?

Code:
a='cut -f2 money'

echo $a

---------- Post updated at 02:41 PM ---------- Previous update was at 02:33 PM ----------

no need to worry iv just figured it out
# 2  
Old 05-21-2012
Try backticks:
Code:
a=`cut -f2 money`

or this:
Code:
a=$(cut -f2 money)

If the result of the cut is more than 1 value, you want to surround both lines of code with doubel quotes like:
Code:
a="$(cut -f2 money)"

This User Gave Thanks to zaxxon For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to compare each file in two directores by storing in variable

In the below bash I am trying to read each file from a specific directory into a variable REF or VAL. Then use those variables in an awk to compare each matching file from REF and VAL. The filenames in the REF are different then in the VAL, but have a common id up until the _ I know the awk portion... (15 Replies)
Discussion started by: cmccabe
15 Replies

2. UNIX for Beginners Questions & Answers

Storing file contents to a variable

Hi All, I was trying a shell script. I was unable to store file contents to a variable in the script. I have tried the below but unable to do it. Input = `cat /path/op.diary` Input = $(<op.diary) I am using ksh shell. I want to store the 'op.diary' file contents to the variable 'Input'... (12 Replies)
Discussion started by: am24
12 Replies

3. UNIX for Advanced & Expert Users

Passing variable as input & storing output in other variable

I have a below syntax its working fine... var12=$(ps -ef | grep apache | awk '{print $2,$4}') Im getting expected output as below: printf "%b\n" "${VAR12}" dell 123 dell 456 dell 457 Now I wrote a while loop.. the output of VAR12 should be passed as input parameters to while loop and results... (5 Replies)
Discussion started by: sam@sam
5 Replies

4. Shell Programming and Scripting

Storing multiple file paths in a variable

I am working on a script for Mac OS X that, among many other things, gets a list of all the installed Applications. I am pulling the list from the system_profiler command and formatting it using grep and awk. The problem is that I want to be able to use each result individually later in the script.... (3 Replies)
Discussion started by: cranfordio
3 Replies

5. Shell Programming and Scripting

Storing lines of a file in a variable

i want to store the output of 'tail -5000 file' to a variable. If i want to access the contents of that variable, it becomes kinda difficult because when the data is stored in the variable, everything is mushed together. you dont know where a line begins or ends. so my question is, how can i... (3 Replies)
Discussion started by: SkySmart
3 Replies

6. Shell Programming and Scripting

[Solved] Value of a variable is not recognised for commands comes from external file

Hi, my script is setting a variable with value and this variable is present in my another command that is coming from external file and this command is internally called after this variable is set. but while execution of this command, the value is not retrieved properly. say, my script... (5 Replies)
Discussion started by: rbalaj16
5 Replies

7. Shell Programming and Scripting

[solved] how to get specific env variable values into a file

greetings! how do i get an env variable that looks like this when echoed: into a file that looks like this: keeping in mind that the two constants are the fields from the env variable will always be in odd positions of the string that need to go into the file AND they will always start... (3 Replies)
Discussion started by: crimso
3 Replies

8. Shell Programming and Scripting

Reading from a file and storing it in a variable

Hi folks, I'm using bash and would like to do the following. I would like to read some values from the file and store it in the variable and use it. My file is 1.txt and its contents are VERSION=5.6 UPDATE=4 I would like to read "5.6" and "4" and store it in a variable in shell... (6 Replies)
Discussion started by: scriptfriend
6 Replies

9. Shell Programming and Scripting

Storing the contents of a file in a variable

There is a file named file.txt whose contents are: +-----------------------------------+-----------+ | Variable_name | Value | +-----------------------------------+-----------+ | Aborted_clients | 0 | | Aborted_connects | 25683... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

10. Shell Programming and Scripting

Storing a variable?

I'm writing a bash shell script to backup several mysql databases. This script will run on a daily basis and send a copy to a remote FTP repository. The filenames are in the format DATE.backup.sql. How do I store the DATE variable so I can delete/move/etc the file on the FTP server the next time... (4 Replies)
Discussion started by: hoover90
4 Replies
Login or Register to Ask a Question