Elementary Shell programming questions

Elementary Shell programming questions

Post by Michael William Buks » Mon, 23 Jan 1995 04:58:08



Hello. I've a couple of (probably elementary) questions about shell
programming. Any help on these, including good references for the novice
shell programmer, would be greatly appreciated.

1) Is it possible to/how does one change the value of a shell or
environment variable from within a subshell?  The application I have
in mind is modifying the display variable with a shell script.

2) Alternatively, I've tried:
     alias disp setenv DISPLAY '"grad"$1":0"'
where the intended result of:  disp 01  would be
     setenv DISPLAY grad01:0
Instead the command is formatted like:
     setenv DISPLAY grad:0 01
Any suggestions on how this approach could be made to work?

Thanks in advance for any help. Replies by e-mail or follow-up posts
are fine.

Mike Buksas
--
Michael W. Buksas       |  Mathematics Department          | Just my opinions,

919/571-1339            |  919/515-7321                    | Or probably yours.
                 http://www2.ncsu.edu/eos/users/m/mwbuksas/www    

 
 
 

Elementary Shell programming questions

Post by S.RamNaray » Tue, 24 Jan 1995 21:20:02




Quote:

>1) Is it possible to/how does one change the value of a shell or
>environment variable from within a subshell?  The application I have
>in mind is modifying the display variable with a shell script.

    You can change the value of the environment variables but they are valid
only within the subshell or the shell you are running. When your application
exits, the environment's original values are restored.

Quote:>2) Alternatively, I've tried:
>     alias disp setenv DISPLAY '"grad"$1":0"'
>where the intended result of:  disp 01  would be
>     setenv DISPLAY grad01:0
>Instead the command is formatted like:
>     setenv DISPLAY grad:0 01

Use the following sequence to insert the parameter into the string
        setenv DISPLAY 'setenv DISPLAY grad\!:1:0'
This (metaparser syntax) is to be given if you are inserting into a string.
If you want to insert the whole of the parameters into the string use '\!*'
instead of the given sequence.
Quote:>Any suggestions on how this approach could be made to work?

>Mike Buksas


 
 
 

Elementary Shell programming questions

Post by MARK G JAH » Wed, 25 Jan 1995 03:43:11



Quote:>Hello. I've a couple of (probably elementary) questions about shell
>programming. Any help on these, including good references for the novice
>shell programmer, would be greatly appreciated.
>1) Is it possible to/how does one change the value of a shell or
>environment variable from within a subshell?  The application I have
>in mind is modifying the display variable with a shell script.
>2) Alternatively, I've tried:
>     alias disp setenv DISPLAY '"grad"$1":0"'
>where the intended result of:  disp 01  would be
>     setenv DISPLAY grad01:0
>Instead the command is formatted like:
>     setenv DISPLAY grad:0 01
>Any suggestions on how this approach could be made to work?

  setenv does not accept any arguments.  It does, although, accept
environment variables.  If $1 were a valid environment variable name
_before_ this alias command was executed then you would get the
correct outcome.



>Thanks in advance for any help. Replies by e-mail or follow-up posts
>are fine.
>Mike Buksas
>--
>Michael W. Buksas       |  Mathematics Department          | Just my opinions,

>919/571-1339            |  919/515-7321                    | Or probably yours.
>                 http://www2.ncsu.edu/eos/users/m/mwbuksas/www    

 
 
 

Elementary Shell programming questions

Post by Joe Morr » Wed, 25 Jan 1995 06:03:40



Quote:> Hello. I've a couple of (probably elementary) questions about shell
> programming. Any help on these, including good references for the novice
> shell programmer, would be greatly appreciated.
> 1) Is it possible to/how does one change the value of a shell or
> environment variable from within a subshell?  The application I have
> in mind is modifying the display variable with a shell script.

Instead of running it as a shell script source it:
Bourne shell derivatives use
. your_script

Csh uses:
source your_script

And your current shell will get any variable changes.
--
        -joe        "Honey, they're in *everybody's* eggs" --firesigns

 
 
 

Elementary Shell programming questions

Post by S. Spencer S » Wed, 25 Jan 1995 12:11:17



Quote:>  setenv does not accept any arguments.  It does, although, accept
>environment variables.  If $1 were a valid environment variable name
>_before_ this alias command was executed then you would get the
>correct outcome.

[...]

This is slightly misleading... setenv "accepts" environment variables
only in the sense that your shell performs variable substitution on
a command line before executing the command(s) that it contains.

--
  S. Spencer Sun / Network Computing Devices, Z-Code Software Division    ____
                                                                          \  /
  Tengo que ir a la tienda a comprar mantequilla y queso.                  \/

 
 
 

1. Elementary redirection question?

Hello

Let's say there is a program on my (solaris) machine called p.

To invoke this program would be

$ p infile outfile arg1 arg2 arg3

What the program does (not written by me) is convert the data from infile
and write it to outfile.

What I would like to do is have the output sent to stdout.

Is there a way of calling this so that instead of writing to outfile that
data is just displayed to the screen instead?

Sorry if this is idiotic ('coz its so simple or 'coz its impossible!).

PS I realise that I could subsequently cat the file

--
thanks
Jeremy

2. Large Hard Disks

3. how elementary are the questions which may be asked on this SIG?

4. Need Xconfig for VGA Wonder / NEC 3V multisync

5. Elementary questions

6. POP3 Error on OS5

7. Elementary question about gnome applets

8. Offline message reader for usenet newsgroups.

9. Solaris 7, Sun Web Server, elementary access-control question

10. A couple elementary questions

11. Very elementary db2 question

12. Some elementary questions

13. elementary usb memory stick question