Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to store number in file for example file number.txt contain 3242 I want to real this file and store its contant in variable for example variable number_var = number.txt so that number_var = 3242

share|improve this question
up vote 3 down vote accepted
number_var=$(cat number.txt)
share|improve this answer

The backtick is your friend:

[madhatta@risby tmp]$ cat foo
[madhatta@risby tmp]$ fred=`cat foo`
[madhatta@risby tmp]$ echo $fred

You had better be pretty sure the file is a one-liner, though; if you import the whole of /boot/vmlinuz into a shell variable, you may start putting pressure on memory!

share|improve this answer

In Bash, ksh and zsh:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.