5

I need to read an entire text file into a shell variable. There is already another thread on this, but it only gives examples for sh and bash:

How to read a file into a variable in shell?

How do I do this in csh?

Sorry for starting a new thread, but I'm new to this site and couldn't comment. How are you supposed to build up your reputation if you can't comment to begin with?

Community
  • 1
  • 1
scoot17
  • 59
  • 1
  • 3
  • Did you try the mentioned methods? Did it work? – pgampe Sep 10 '16 at 22:31
  • 1
    I did, but it did not work. I think in csh you have to use the "set" command. I tried the following, but that did not work either: set value=`cat config.txt` and set value=$( – scoot17 Sep 10 '16 at 23:04
  • What are you trying to solve? Perhaps just keep a variable with the filename, and use that instead? – cnst Sep 10 '16 at 23:41
  • I think it's quite likely that csh lacks the syntax to do it, and there's no way to do it externally, either, see http://stackoverflow.com/questions/496702/can-a-shell-script-set-environment-variables-of-the-calling-shell – cnst Sep 10 '16 at 23:45
  • I need to insert the contents of config.txt into a C-shell script. – scoot17 Sep 10 '16 at 23:48

2 Answers2

0

You can use

set value=`cat myfile`
asm0dey
  • 2,841
  • 2
  • 20
  • 33
0

Use:

setenv VAR `cat my_file`

If you want use it for concat a variable (that is my need):

setenv VAR `cat my_file`$VAR
Welgriv
  • 714
  • 9
  • 24