-1

So i'm starting to get addicted to POSIX standards and simplicity yet i hate not having autocomplete using the arrows to go through characters and i want a cool shell prompt.

so is there anyway that i could have something like fish or Zsh or even bash on the front end so i can have autocomplete, a nice and informative prompt, being able to go forward and backward on the command with arrows but when i press enter the command itself is ran by Dash instead of the interactive thing unless the script requires bash fish or etc in the shebang?

i just want to feel comfortable when typing the command the rest can be harsh and simple i'm using Konsole although i'm thinking to changing to a console prompt that allows Überzug(yes i'm aware that GUI's exist for a reason, its just for LF)also forgot although sh redirects to dash on konsole i told it to go for bash

6
  • You could try rlwrap dash but output can be strange after hitting enter (prompt handling + duplicated line).
    – A.B
    Jul 4, 2021 at 18:46
  • @A.B i've though of just piping it throught dash ie "command" | dash but does it really work or is it just an ilusion
    – Imeguras
    Jul 4, 2021 at 19:47
  • 2
    What difference does it make whether some external command is run by dash or some other shell?
    – muru
    Jul 5, 2021 at 2:01
  • @muru its considerably faster i guess
    – Imeguras
    Jul 5, 2021 at 10:00
  • 1
    Not faster than your input speed
    – muru
    Jul 5, 2021 at 10:10

1 Answer 1

1

I thought I might have misunderstood your question, because what you seem to be asking for is pretty much the way most everyone operates anyway. We use an interactive shell for, well, interaction. But we expect that scripts are often run by a different shell.

This typically "just works", since the vast majority of the scripts you will execute will include a shebang line. That way the script itself can request the interpreter closest to the feature set it needs. If it needs POSIX compatibility, it should specify either:

#!/usr/bin/sh

or

#!/usr/bin/env sh

That may be dash (on Debian/Ubuntu flavors), or it could be BusyBox's ash (on Alpine), or something else. It's up to the distribution itself to make sh point to the most POSIX compliant shell that it provides by default. In the distant past, in some (most?) cases, this was even bash.

In the rare event that someone leaves out the shebang, well, be suspicious of the rest of the code-quality for starters. But running it isn't a problem -- Just sh scriptname.sh.

But no one expects you to actually operate interactively under today's basic shells interactively. Personally, I use fish, which is the furthest of the ones you mentioned from any form of POSIX compliance. But I can write my scripts in fish (preferably, since it has a much more modernized scripting language) or POSIX, if I need portability. And it doesn't matter, since it's the shebang that handles that.

The one area where this isn't the case is for scripts that need to be sourced, since they change the environment of the current shell instance. These do not get executed with the shebang-specified interpreter, but are executed by the interactive shell itself. I rarely find this to be a problem myself, since most all of the software that I use provides a fish config file if needed. But in those rare instances when you really do need to source a POSIX file, there are utilities such as bass and others to help you do this.

For bash and zsh, this isn't even a problem, since most all config files are written to a lowest-common-denominator that they can be sourced in the "close-enough-to-POSIX-to-not-matter" Zsh and bash.

2
  • thanks! so if i use "sudo ln -sfT dash /usr/bin/sh" on the /bin library does that mean that has long as a script has a sh shebang would it run on dash even if i have zsh as a shell prompt(i prefered it since its still has a bit of posix compliance so i don't have to learn a complete new thing)
    – Imeguras
    Jul 6, 2021 at 2:23
  • Yes, as long as the sh shebang is there, executing it (but not sourcing it) will run it in dash, assuming dash is your /usr/bin/sh. That said, I don't recommend redefining /usr/bin/sh. It's probably already dash, but it's distribution dependent. Jul 6, 2021 at 3:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.