simple question about shell command syntax

simple question about shell command syntax

Post by Stev » Wed, 25 Aug 1999 04:00:00



I have a simple question about command syntax in the Korn or Bourne shells.
Specifically, about the differences between the following commands:

./myscript

. myscript

I notice that the first syntax does not do what I want it to do => namely,
to update any changes to variables, etc.

Does the . <space> syntax (as seen in the second command) imply an implicit
export for all variables declared or changed within the subshell that runs
the script?

I am more used to using tcsh, so I usually just use "source ./myscript" but
this does not appear to be valid in the ksh or bsh.

Regards

Steve

 
 
 

simple question about shell command syntax

Post by Owen M. Astle » Wed, 25 Aug 1999 04:00:00



Quote:>I have a simple question about command syntax in the Korn or Bourne shells.
>Specifically, about the differences between the following commands:

>./myscript

>. myscript

./myscript tries to run the executable myscript in the current directory
(./).  If this is a shell script, or if the shell thinks that it is, then
it will be run in a new shell, so any new variables set will only be for
that shell invocation.

Quote:>Does the . <space> syntax (as seen in the second command) imply an implicit
>export for all variables declared or changed within the subshell that runs
>the script?

. myscript

Does the equivalent of source in tcsh (some shells search through PATH to
find the file), ie it is run in the current shell.

From the ksh man page:

. file [argument ...]1
  Reads the complete file and executes the commands.  The commands are
  executed in the current shell environment.  The search path specified by
  PATH is used to find the directory containing file.  If any arguments
  are specified, they become the positional parameters.  Otherwise, the
  positional parameters are unchanged.  The exit status is the exit status
  of the last command executed.

Quote:>I am more used to using tcsh, so I usually just use "source ./myscript" but
>this does not appear to be valid in the ksh or bsh.

source isn't a command in ksh, but it should be in bash.

Owen

 
 
 

simple question about shell command syntax

Post by Hunter Johns » Wed, 25 Aug 1999 04:00:00




> I have a simple question about command syntax in the Korn or Bourne shells.
> Specifically, about the differences between the following commands:
> ./myscript

This runs myscript regularly and looks only in the current directory
for myscript.

Quote:> . myscript

This runs myscript as if it were typed in to the current shell process
and looks through your path for myscript.  The '.'s in those two
commands have nothing in common.

Quote:> I notice that the first syntax does not do what I want it to do => namely,
> to update any changes to variables, etc.

Yup.

Quote:> Does the . <space> syntax (as seen in the second command) imply an implicit
> export for all variables declared or changed within the subshell that runs
> the script?

Kind of.

Quote:> I am more used to using tcsh, so I usually just use "source ./myscript" but
> this does not appear to be valid in the ksh or bsh.

Right; the sh equivalent of csh's 'source' is '.'

Hunter
--
J. Hunter Johnson        | "A little consistent wholesome modeling and

(937) 865-6800 x5385     |    true words harshly spoken."
Lexis-Nexis, Dayton, OH  |                               -- Ron Sider

 
 
 

simple question about shell command syntax

Post by Andrei Ivan » Wed, 25 Aug 1999 04:00:00



> I have a simple question about command syntax in the Korn or Bourne shells.
> Specifically, about the differences between the following commands:

> ./myscript

In this case new instance [copy] of the running shell is created, where
'myscript' is evaluated. Once this script is completed, this new shell
instance terminates as well.

Quote:> . myscript

Here 'myscript' is evaluated in the current shell, so all assignments
will remain valid after script's termination (it's usual to type in
". .profile" to apply changes made in the .profile file). Effect is
just the same as of "source myscript" in C-shell environment.

--
andrei

 
 
 

1. Simple shell command question

I would like to have a shell script (C-Shell) change it's group during
execution. I would also like to have the capability of this script to
change the owner during execution. Any suggestions on the lines of code
that would be necessary to do this? If possible, I'd like the script to
remember what group/owner it originally had and switch itself back to
those settings just before it ends. Thanks.

2. HELP: shared library

3. syntax error with "cp" in simple file back up shell script

4. Newbie Question

5. shell command option syntax

6. Solaris for Intel?

7. Simple .htaccess syntax question

8. Copying a DOS disk to UNIX.

9. paste command syntax question

10. dd command syntax question

11. Survey Question: Do you use the syntax diagrams in the AIX command documents?

12. Very Simple Shell Needed (CD command)-Newbie here

13. recursive shell commands, is there a simple one?