|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
xterm default shell differences between OpenBSD and FreeBSD/NetBSD
I digested about 1/3 of a book on shell scripting and have been trying to add weather information to an openbox window manager.
The following works with the default shell in FreeBSD and NetBSD: ~/scripts/weather.sh Code:
#!/bin/sh curl -sk http://weather.noaa.gov/pub/data/observations/metar/decoded/KYKM.TXT | \ fold -w 78 -s echo "" read -p "<Enter to Close>" nothing Code:
xterm -g 78x16+150+38 -T "Yakima, WA Weather" -e ~/scripts/weather.sh Using $ xterm -hold -e ~/scripts/test.sh I get the following:Code:
YAKIMA AIR TERMINAL, WA, United States (KYKM) 46-34N 120-32W 324M Jan 04, 2016 - 04:53 PM EST / 2016.01.04 2153 UTC Wind: Calm:0 Visibility: 10 mile(s):0 Sky conditions: mostly cloudy Temperature: 30.0 F (-1.1 C) Dew Point: 21.9 F (-5.6 C) Relative Humidity: 71% Pressure (altimeter): 29.82 in. Hg (1009 hPa) ob: KYKM 042153Z 00000KT 10SM BKN014 M01/M06 A2982 RMK AO2 SLP112 T10111056 cycle: 22 ./test.sh[5]: read: -p: no coprocess Last edited by shep; 5th January 2016 at 02:51 AM. Reason: added output from OpenBSD 5.8 |
|
|||
I always use printf(1) to print/echo the prompt.
Code:
#read -p "<Enter to Close>" nothing printf "<Enter to Close> " ; read nothing $ xterm -e 'shep.sh' the new xterm prompts me properly and only closes when I press the Enter key;Code:
[snip] ressure (altimeter): 29.82 in. Hg (1009 hPa) ob: KYKM 042358Z 08004KT 10SM SCT018 BKN070 BKN100 M02/M06 A2982 RMK AO2 T10221061 cycle: 0 <Enter to Close>
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
Thanks
|
|
|||
I want to resurrect this to clear up some ambiguities:
Your question isn't at all about xterm--it's about the /bin/sh program on the different BSDs. xterm is a terminal emulator. That means it emulates hardware, in this case most often a vt220 with color. It doesn't care about the software running inside it (including but not limited to the shell). It is the shell that is executing your script and the differences between /bin/sh on OpenBSD vs. the other BSDs is what matters here. On FreeBSD, DragonFly BSD, and NetBSD, /bin/sh is ash--the Almquist shell. A modified version of this shell is used for Debian's /bin/sh (dash, the Debian Almquist shell). However, on OpenBSD, /bin/sh is effectively a hardlink to /bin/ksh; in other words, /bin/sh on OpenBSD is ksh (Korn shell). Now here's where things go awry: read is a shell built-in. That means it is something handled by the shell and is not guaranteed to work the same way between shells. And indeed, that matters here, because the ksh read built-in is quite different from the one in ash. Additionally, your use of echo suffers from the same fate; calling it unqualified like that will use the shell built-in instead of /bin/echo. And again, the echo built-in is different between ksh and ash. And even /bin/echo is not guaranteed to be the same between *BSD and SYSV (there are historical differences). So if you care about portability, it is best to never use options with built-ins unless you can guarantee such an option will always be handled the same way on all shells (POSIX mandates a theoretical POSIX /bin/sh) and to use fully qualified external commands, such as /usr/bin/printf. |
|
||||
For some reason many people are confused about that. I once remember someone insisting that there's no difference between the terminal and shell :-/
At any rate, "What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?" might be worth reading as well.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
|||
Quote:
. The problem I ran into with the book I purchased is that different syntax specifications for the various shells were scattered all through the book. Although I have a rough idea about operators, declaring variables and flow, I am not at all facile with OpenBSD's modified Korn shell. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Underlegend Networks - NetBSD free shell server | muflon | Off-Topic | 1 | 8th September 2015 01:53 PM |
Differences between the Linux and BSD world summarized | harishankar | Other OS | 6 | 18th December 2013 12:05 PM |
xterm is not a login shell except on blackbox | daemonfowl | NetBSD General | 6 | 1st August 2012 03:59 AM |
Differences in processing in POWER CPUs. | Ninguem | General Hardware | 5 | 25th August 2011 03:30 PM |
BSD UNIX Toolbox: 1000+ Commands for FreeBSD, OpenBSD and NetBSD | anomie | Book reviews | 8 | 28th July 2008 09:32 PM |