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

link|improve this question

feedback

3 Answers

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

The backtick is your friend:

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

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!

link|improve this answer
feedback

In Bash, ksh and zsh:

number_var=$(<number.txt)
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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