Home > Archive > Unix Programming > April 2005 > Running same unix script in different shells
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Running same unix script in different shells
|
|
| c_jena@ureach.com 2005-04-08, 8:58 am |
| How can I port same shell script in to different shells like C Shell, K
Shell and Bourne Shell
Chitta
| |
| Pascal Bourguignon 2005-04-08, 4:00 pm |
| c_jena@ureach.com writes:
> How can I port same shell script in to different shells like C Shell, K
> Shell and Bourne Shell
Launching your favorite editor, reading the man page of the source and
the target shell, thinking, and editing the script file.
Also, it's possible to write a single source file usable both in csh,
sh, Fortran and C, and perhaps it would be possible to add more
languages, so you would not need to "port" the script...
happy.source:
------------------------------------------------------------------------
cat /*dev/null; echo "Happy New Year"\!
cat <<c*/ /*dev/null | cat > /dev/null
c */ () {} /*
c */ main() { cat(); printf("Happy New Year!\n"); } /*
17 format('Happy New Year!')
write (6,17)
stop
end
c*/
------------------------------------------------------------------------
Makefile:
------------------------------------------------------------------------
all: happy-c happy-f happy-sh happy-csh
happy-c:happy.source Makefile
@ cp happy.source happy-c.c
@ gcc -o happy-c happy-c.c
@ echo -n '(C) '
@ ./happy-c || true
happy-f:happy.source Makefile
@ cp happy.source happy-f.f
@ f77 -o happy-f happy-f.f 2> /dev/null
@ echo -n '(FORTRAN) '
@ ./happy-f
happy-sh:happy.source Makefile
@ cp happy.source happy-sh
@ echo -n '(Bourne Shell) '
@ chmod 755 happy-sh
@ sh ./happy-sh
happy-csh:happy.source Makefile
@ cp happy.source happy-csh
@ chmod 755 happy-csh
@ echo -n '(C Shell) '
@ csh ./happy-csh
clean:
-rm -f *.o *~ happy-csh happy-sh happy-f happy-f.f happy-c happy-c.c
------------------------------------------------------------------------
--
__Pascal Bourguignon__ http://www.informatimago.com/
In a World without Walls and Fences,
who needs Windows and Gates?
| |
| Ralf Fassel 2005-04-08, 4:00 pm |
| * Pascal Bourguignon <spam@mouse-potato.com>
| happy.source:
kEWl, D00dE.
R'
| |
| Heiner Steven 2005-04-18, 8:58 pm |
| c_jena@ureach.com wrote:
> How can I port same shell script in to different shells like C Shell, K
> Shell and Bourne Shell
Since the KornShell was designed to be a compatible replacement
of the Bourne Shell, it's easy to write a script that runs
with both shells. Just limit yourself to the Bourne Shell
constructs, which are understood by both shells.
The C-Shell is something completely different, inventing
a completely independent command language. The Bourne Shell
and C-Shell command sets are disjoint by a large degree.
The following script shows, that it still is possible to
use all together in one script:
http://www.shelldorado.com/scripts/cmds/shtype
Heiner
--
___ _
/ __| |_ _____ _____ _ _ Heiner STEVEN <heiner.steven@nexgo.de>
\__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
|___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
|
|
|
|
|