A lot of people call set -euo pipefail
the "strict mode" for bash programming, as a reference to "use strict";
in JavaScript.
In other words, always add this if you want to stay sane unless you're a shellcheck user.
Hint: :q!
Sister communities:
Community rules (click to expand)
1. Follow the site-wide rules
sudo
in Windows.Please report posts and comments that break these rules!
Important: never execute code or follow advice that you don't understand or can't verify, especially here. The word of the day is credibility. This is a meme community -- even the most helpful comments might just be shitposts that can damage your system. Be aware, be smart, don't fork-bomb your computer.
A lot of people call set -euo pipefail
the "strict mode" for bash programming, as a reference to "use strict";
in JavaScript.
In other words, always add this if you want to stay sane unless you're a shellcheck user.
People call set -euo pipefail
strict mode but, it's just another footgun in a language full of footguns. Shellcheck is a fucking blessing from heaven though. I wish I could forcibly install it on every developer's system.
I have written 5 shell scripts ever, and only 1 of them has been more complex than "I want to alias this single command"
I can't imagine being an actual shell dev
only 1 of them has been more complex than “I want to alias this single command”
I have some literal shell aliases that took me hours to debug...
I do not envy you.
Nah, it's in the past.
But people, if you are writing a command that detects a terminal to decide to color its output or not, please add some overriding parameters to it.
It really isn't bad especially if you use ash
just use python instead.
subprocess.run()
, to call to system utilspathlib.Path
for file paths and reading/writing to filesshutil.which()
to resolve utilities from your Path
env varHere's an example of some python i use to launch vscode (and terminals, but that requires dbus
)
from pathlib import Path
from shutil import which
from subprocess import run
def _run(cmds: list[str], cwd=None):
p = run(cmds, cwd=cwd)
# raises an error if return code is non-zero
p.check_returncode()
return p
VSCODE = which('code')
SUDO = which('sudo')
DOCKER = which('docker')
proj_dir = Path('/path/to/repo')
docker_compose = proj_dir / 'docker/'
windows = [
proj_dir / 'code',
proj_dir / 'more_code',
proj_dir / 'even_more_code/subfolder',
]
for w in windows:
_run([VSCODE, w])
_run([SUDO, DOCKER, 'compose', 'up', '-d'], cwd=docker_compose)