Will a shell script execute in Solaris? if not, which is the fastest way to make it compatible
Assuming your script is portable, i.e. doesn't use bashisms, GNUisms, or whatever non POSIX, it should work with most Unix and Linux OSes with its #!/bin/sh
shebang.
However under Solaris 10 and older, /bin/sh
is not the POSIX shell but the legacy Bourne shell which predates POSIX and is then missing features that came later with the standard.
Your script is then likely to break if left as is but this can easily be fixed by setting the shebang to point to the POSIX compliant Solaris shell this way:
#!/usr/xpg4/bin/sh
To make sure you'll also pick the POSIX compliant utilities when they differ from the default Solaris ones, you should also put the following line early in your script:
PATH=$(getconf PATH):PATH
Related videos on Youtube
![Arosha Perera](https://i.stack.imgur.com/OcO3M.jpg?s=256&g=1)
Arosha Perera
Updated on September 18, 2022Comments
-
Arosha Perera almost 2 years
I am sending a request XML to the URL and receiving a zip file to the given path. Sometimes I'm facing troubles when the bandwidth is low this zip file, most likely 120MB size is not getting downloaded properly. And getting an error when extracting the zip file. Extracting happens from the code as well. When I download in high bandwidth this file gets download without issue.
I'm looking for a solution without making the bandwidth high, from program level are there any ways to download this zip file, may be part by part or something like that? Or anyother solution that you all are having is highly appreciated.
Downloading :
url = new URL(_URL); sc = (HttpURLConnection) url.openConnection(); sc.setDoInput(true); sc.setDoOutput(true); sc.setRequestMethod("POST"); sc.connect(); OutputStream mOstr = sc.getOutputStream(); mOstr.write(request.getBytes()); InputStream in = sc.getInputStream(); FileOutputStream out = new FileOutputStream(path); int count; byte[] buffer = new byte[86384]; while ((count = in.read(buffer,0,buffer.length)) > 0) out.write(buffer, 0, count); out.close();
Extracting :
try { ZipFile zipFile = new ZipFile(path+zFile); Enumeration<?> enu = zipFile.entries(); while (enu.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enu.nextElement(); String name = path+"/data_FILES/"+zipEntry.getName(); long size = zipEntry.getSize(); long compressedSize = zipEntry.getCompressedSize(); System.out.printf("name: %-20s | size: %6d | compressed size: %6d\n", name, size, compressedSize); File file = new File(name); if (name.endsWith("/")) { file.mkdirs(); continue; } File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[86384]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); } catch (Exception e) { log("Error in extracting zip file "); e.printStackTrace(); }
-
Elliott Frisch over 9 yearsYou need to clarify your question; usually solaris
/bin/sh
isn'tbash
but that doesn't mean you must write a script inksh
. For one thing, what version of solaris and does it havebash
? Try#!/usr/bin/env bash
-
nobody over 9 yearsWhy not just try it?
-
chepner over 9 yearsTry it, and if it doesn't work, you can come back and ask about any specific errors you don't understand.
-
Keith Thompson over 9 yearsEvery UNIX-like system has a shell at
/bin/sh
. If you avoid features specific either to bash or to ksh, there shouldn't be a problem. -
Keith Thompson over 9 years@jlliagre:
/bin/sh
does exist on Solaris. Why would using it be a problem? Is it an older version of the shell? -
jlliagre over 9 years@KeithThompson That's indeed the problem. /bin/sh is the original non POSIX legacy Bourne Shell. It breaks with most current /bin/sh scripts thus /usr/xpg4/bin/sh should be used.
-
-
jlliagre over 9 yearsNot sure why this was accepted as this is not the correct reply. On Solaris,
/usr/bin
is a symbolic link to/bin
so#!/bin/sh
and#!/usr/bin/sh
work identically . -
Naveen Dennis over 9 years@jlliagre: As I mentioned I have no means of testing it. Please do leave a response stating the way in which a shell script could be made compatible to run in a Solaris system