Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Safe to assume sh being installed?

I'm working on a series of command lines to create files, set variables and such on Linux systems. I cannot tell which shell will actually be used during execution but I do know that it will be one of csh, tcsh, sh, ksh, or bash.

csh and tcsh not being bourne compatible is my main issue at this point since they use different commands/syntax for both setting variables and conditional expressions.

I could simply create a shell script with a shebang to switch to /bin/sh if it is safe to assume it being present.

Therefore I'm wondering: Is it safe to assume sh being installed and available or is there another more elegant way to handle the different shell styles without creating seperate scripts?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It is safe to assume that there is a sh in POSIX compatible systems, but its path may vary. The Open Group specification says to determine the location of the standard sh utility with:

command -v sh

So you could do something like:

"`command -v sh`" <<EOS
echo my super sh script
EOS

But there's a problem: csh doesn't support quoted heredocs, which will make the process of writing the script a real pain.

As you're targeting Linux, you might directly write a sh script and use the shebang #!/bin/sh or #!/usr/bin/env sh.

Take notice that the variables set in the script won't be available to the parent shell. For that you need to source the script, in which case the syntax will matter and you'll have to write at least both sh and csh versions of it.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!