Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda