Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3214282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:02:33+00:00 2026-05-17T15:02:33+00:00

The main question here is: is there a standard method of writing UNIX shell

  • 0

The main question here is: is there a standard method of writing UNIX shell scripts that will run on multiple UNIX platforms.

For example, we have many hosts running different flavours of UNIX (Solaris, Linux) and at different versions all with slightly different file system layouts. Some hosts have whoami in /usr/local/gnu/bin/, and some in /usr/bin/.

All of our scripts seem to deal with this in a slightly different way. Some have case statements on the architecture:

case "`/script/that/determines/arch`" in 
  sunos-*) WHOAMI=`/usr/local/gnu/bin/whoami` ;;
  *)       WHOAMI=`/usr/bin/whoami` ;;
esac

With this approach you know exactly what binary is being executed, but it’s pretty cumbersome if there are lots of commands being executed.

Some just set the PATH (based on the arch script above) and call commands by just their name. This is convenient, but you lose control over which command you run, e.g. if you have:

/bin/foo
/bin/bar
/other/bin/foo
/other/bin/bar

You wouldn’t be able to use both /bin/foo and /other/bin/bar.

Another approach I could think of would to have a local directory on each host with symlinks to each binary that would be needed on each host. E.g.:

Solaris host:

/local-bin/whoami -> /usr/local/gnu/bin/whoami
/local-bin/ps -> /usr/ucb/ps

Linux host:

/local-bin/whoami -> /usr/bin/whoami
/local-bin/ps -> /usr/ps

What other approaches do people use? Please don’t just say write the script in Python… there are some tasks where bash is the most succinct and practical means of getting a simple task accomplished.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T15:02:33+00:00Added an answer on May 17, 2026 at 3:02 pm

    I delegate all this to my .profile, which has an elaborate series of internal functions to try likely directories to add to the PATH. Except on OSX, which I believe is basically impossible because Darwin/Fink/Ports each wants to control your PATH, this approach works well enough.

    If I cared about ambiguity (multiple instances of foo in different directories on my PATH), I would modify the functions so as to identify all ambiguous commands and require manual resolution. But for my environment, this has never been an issue. My main concern has been to have a single .profile that runs on Debian, Red Hat, Solaris, BSD, and so on. The ‘try every directory that could possibly work’ approach works well enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the main question I guess : Is there a .NET way to get
Quick question, is there a way to call your main method whatever you like
My main question is : Is there a good practice to serve binary files
This may be an obvious question, but I think there may well be multiple
Main question is what are the implications of allowing the this keyword to be
My main question is given a feature centroid, how can I draw it in
The title is the main question. The exact scenario (I am 'using namespace std;'):
This was the main question posed by Greg Wilson's bits of evidence presentation. I'm
first of all, my main question: What are some good troubleshooting techniques when you
I am using Struts2, Spring 2 and Junit 4.5. My main question is, whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.