DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 4th January 2016
shep shep is offline
Rc.conf Instructor
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 963
Default 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
Which I call with the following openbox menu entry
Code:
xterm -g 78x16+150+38 -T "Yakima, WA Weather" -e ~/scripts/weather.sh
When I try the same script/menu entry in OpenBSD the xterm does not wait for "read" input and closes immediately.

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
Ideally, I would like the scripts to be portable. Can someone give me a brief explanation and suggestions about how to script this for OpenBSD? Ultimately, I would like to pass the output into a dialog program like zenity or yad.

Last edited by shep; 5th January 2016 at 02:51 AM. Reason: added output from OpenBSD 5.8
Reply With Quote
  #2   (View Single Post)  
Old 5th January 2016
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 3,496
Default

I always use printf(1) to print/echo the prompt.
Code:
#read -p "<Enter to Close>" nothing
printf "<Enter to Close> " ; read nothing
When I invoke the script with $ 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
Reply With Quote
  #3   (View Single Post)  
Old 5th January 2016
shep shep is offline
Rc.conf Instructor
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 963
Default

Thanks
Reply With Quote
  #4   (View Single Post)  
Old 18th January 2016
ibara's Avatar
ibara ibara is offline
AsiaBSDCon 2016 Speaker
 
Join Date: Jan 2014
Posts: 403
Default

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.
Reply With Quote
  #5   (View Single Post)  
Old 18th January 2016
Carpetsmoker's Avatar
Carpetsmoker Carpetsmoker is offline
Real Name: Martin
Old man from scene 24
 
Join Date: Apr 2008
Location: Dutchman living in the UK
Posts: 2,174
Default

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.
Reply With Quote
  #6   (View Single Post)  
Old 18th January 2016
shep shep is offline
Rc.conf Instructor
 
Join Date: May 2008
Location: Dry and Dusty
Posts: 963
Default

Quote:
Originally Posted by ibara View Post
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.
I thought this line clarified that I was using the default shells in the respective BSD's
Quote:
Originally Posted by shep View Post
The following works with the default shell in FreeBSD and NetBSD:
.

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 01:00 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick