Is "sh file" equivalent to "cat file | sh"

Is "sh file" equivalent to "cat file | sh"

Post by Marc Baudo » Tue, 25 Jan 1994 19:35:46



I'd like to know if "sh file" is exactly the same as "cat file | sh". If there
is any difference, what is it? I'd like to know that in order to write a
utility program to unshar a bunch of files, passing the lines to sh via a
pipe.

--
                       ___   __    ___   __    ___  __
 Marc Baudoin         /  /  /  \  /  /  /  \  /    /  \  /   /   Babassez-vous
 le babasseur fou    /  \  /---/ /  \  /---/ /--  /   / /   /    les uns

 
 
 

Is "sh file" equivalent to "cat file | sh"

Post by B.N.Blackmo » Tue, 25 Jan 1994 23:55:47



> I'd like to know if "sh file" is exactly the same as "cat file |
> sh". If there is any difference, what is it? I'd like to know that
> in order to write a utility program to unshar a bunch of files,
> passing the lines to sh via a pipe.

The two are NOT the same, but for your purposes the difference should
not matter. The difference is that "sh file" reads commands from the file
directly leaving standard input available for the script to read user
input from while "cat file|sh" (or better "sh < file") takes its commands
from standard input and so can't get any commands from the user using
this method.

--
Brian Blackmore, Darwin College, The University of Kent at Canterbury, UK.
Beyond the shadow of a dream who knows what lies

 
 
 

1. dowhat=`expr "dowhat.sh" : "\(.*\)\.sh$"`;

This is from a Bash shell script.  The purpose is to get at the base
name of the script (which is contained within the script variable $0),
using the regular expression mode of expr.

.* matches 0 to infinity (the *) chars (the .) except for a newline,
and the escaped parentheses are needed to encapsulate that expression
for some reason. \.sh$ specifies ".sh" occurring at the end of a line
(escape needed to specify a literal .).

Please explain how this strips off the .sh extension.  If you enter
dowhat.sh in Emacs, and search using this regular expression, it
happily matches the whole shebang, whereas as used in the script, the
extension is subtracted!

Good regular expressions tutorial:
http://www-105.ibm.com/developerworks/education.nsf/linux-onlinecours...

2. Need Help...

3. more secure?: "#!/bin/sh -" or "#!/bin/sh"

4. PATCH: wireless uses __init

5. GETSERVBYNAME()????????????????????"""""""""""""

6. Where is SATAN Distribution?

7. sh says: test "$1" = "" when $1="-b"

8. zsh help !

9. """"""""My SoundBlast 16 pnp isn't up yet""""""""""""

10. "Standard Journaled File System" vs "Large File Enabled Journaled File System"

11. CygWin - PATH finds "myscript.sh" but not "myscript"

12. ":" v. "#!/bin/sh"

13. make "perl sh_script", "sh sh_script" both work