It is currently Sat, 26 Nov 2022 06:58:28 GMT



 
Author Message
 file contents into variable, or global variable from shell script

I want to maintain a filename across editing sessions (i access my
editor through csh shell scripts).  I have two choices

1) shell script writes filename to file, reads it later.  This requires
a shell command to read first word of a file into a variable - I don't
know how to do this - can you help?

2) shell script defines global variable as filename.  I don't know how
to do this either (the variable goes away when the script completes).

Any suggestions appreciated, please use email

thanks
/jeff  (jwins...@wireless.tellabs.com)



 Sat, 15 Jan 2000 03:00:00 GMT   
 file contents into variable, or global variable from shell script

Public questions deserve public answers. Bourne shell script, as I
remember it, expand to your heart's content:
--------------------------------------------------
        [ "$1" ] && {
                echo $1 >.vv
                vi $1
                exit
                }
        [ "$1" ] || vi `cat .vv`
-------------------------------------------------
Now, how hard was that?
--
Kurt J. Lanza
k...@infor.com



 Sat, 15 Jan 2000 03:00:00 GMT   
 file contents into variable, or global variable from shell script

Let's see:

flybane 99% echo '#\!/usr/bin/sh' > foo.sh
flybane 100% echo 'read name' >> foo.sh
flybane 101% echo 'echo $name' >> foo.sh
flybane 102% chmod +x foo.sh
flybane 103% set a = `foo.sh < foo.sh`
flybane 104% echo $a
#!/usr/bin/sh

Is that sort of what you had in mind?  See the man page for 'read'

David S.
davids
...     @fllybane.berkeley.edu



 Sat, 15 Jan 2000 03:00:00 GMT   
 file contents into variable, or global variable from shell script

Am I missing something? Why this indirection?
How about this:

% echo filename >somewhere

% set a=`cat somewhere`

Sure 'a' is not just the first word after this, but that should be o.k.
in your case.

Stephen

'+,        .+'''+.         .+'''+.         .+'''+.         .+'''+.
Stephen Friedrich \       /  e-mail: 1frie...@informati.uni-hamburg.de
   '+...+'         '+...+'         '+...+'         '+...+'         '+.



 Sun, 16 Jan 2000 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. shell scripting: echoing contents of contents of variable

2. How do i transfer the contents of shell variable to a variable used in C program

3. Executing contents of variable in shell script

4. file contents into shell/env variable

5. global shell environment variable

6. global variables in shell

7. global shell variables

8. Using global variables in a sh-script

9. export variables to calling shell in a shell-script

10. Shell Variables: Shell prompt OK, script, NO.


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software