awoodsnet,
@awoodsnet@phpc.social avatar

what do you wish was easier about Bash scripting?

#Bash #ShellScript #CLI

scy,
@scy@chaos.social avatar

@awoodsnet Getting return codes out of individual components of pipes.

Making people understand what bashisms are and that they can’t be testing scripts with a shebang of #!/bin/sh with just bash.

Getting structured data out from stuff that’s running in subshells, like setting variables from something in a | while read loop.

jrf_nl,
@jrf_nl@phpc.social avatar

@awoodsnet That I didn't have to remember as much... oh and scripting cross-OS....

awoodsnet,
@awoodsnet@phpc.social avatar

@jrf_nl Cross OS scripting is important. I’m a Mac user, but want to be able to re-use on a linux server or a docker container

Just not Windows! That’s a bridge too far ! 😛

jrf_nl,
@jrf_nl@phpc.social avatar

@awoodsnet Windows user here. I'm always the one who has to try to figure out how to make scripts work for me as they only ever work on Linux/MacOS.

awoodsnet,
@awoodsnet@phpc.social avatar

@jrf_nl I’m not planning to do anything too crazy. So it should be pretty simple. If you use Bash in WSL, you “should” be fine (fingers crossed). I don’t have access to a Windows box. so I won’t be able test for that. I’m in my planning stage. As I make more progress rewriting Opal, we’ll start to see how things shape up

jrf_nl,
@jrf_nl@phpc.social avatar

@awoodsnet Ah, but I don't use WSL. A lot of what I work on are (PHP-based) CLI tools, so I generally need to test in the native environment, aka no WSL 🤷‍♀️

willpower232,
@willpower232@phpc.social avatar

@awoodsnet literally everything, its easier to write a short PHP script that executes shell commands than to wrangle string manipulation in bash

awoodsnet,
@awoodsnet@phpc.social avatar

@willpower232 i don’t disagree. PHP will always be there for you. But I’ll see what I can do to improve the Bash string experience

willpower232,
@willpower232@phpc.social avatar

@awoodsnet thank you in advance for your service 🙏

ondrej,
@ondrej@sury.org avatar

@awoodsnet The implicit sub-shelling in the pipelines (especially the while-loop problem) is confusing.

The return codes from pipelines is also confusing.

dmnelson,
@dmnelson@mastodon.social avatar

@awoodsnet Pros: It’s just piping the output of one command into another.

Cons: It’s just piping the output of one command into another.

😄

aev,
@aev@mastodon.sdf.org avatar

@awoodsnet Clarity.

alexch,
@alexch@ruby.social avatar

@awoodsnet syntax

mistersql,
@mistersql@mastodon.social avatar

@awoodsnet no sensible module/packaging
functions don't have named arguments
expressions in if-blocks are baroque
complex datatypes are so bad that you have to use json + jq & keep your data structures out of bash data structures as long as possible

fish & xonsh & powershell are the most interesting alternatives, but they all want to keep backwards compat in some sense & that really keeps them all making bad design choices

scottjenson,
@scottjenson@social.coop avatar

I'd like a REPL type editor where I could get the output (or sample output) on each line as I hover. This would allow me to visualize variables or see the expected results and I work my way through the script.

ramsey,
@ramsey@phpc.social avatar

@scottjenson Oooh! This would be awesome!

Crell,
@Crell@phpc.social avatar

@awoodsnet Quoting/escaping is a mess.

Conditionals are just weird.

I've never been able to figure out variable scoping.

Function params are nonsensical.

awoodsnet,
@awoodsnet@phpc.social avatar

@Crell these are excellent criticisms. i totally agree.

As for scope, its basically the opposite of PHP - bash is global by default, and you need to use the local keyword to confine it to the function. there is no block scope.

ramsey,
@ramsey@phpc.social avatar

@awoodsnet Documentation

awoodsnet,
@awoodsnet@phpc.social avatar

@ramsey what about documentation do you find difficult? you don’t like the man pages?

ramsey,
@ramsey@phpc.social avatar

@awoodsnet All of it is pretty difficult to find anything. I end up searching the web, and I have to look at multiple blog posts with ads popping up all over and the pages jumping around while loading before I’m able to find information that helps.

That said, I love Bash, and I would consider myself mostly an expert in it, but it’s still difficult to find good quality docs on it.

awoodsnet,
@awoodsnet@phpc.social avatar

@ramsey totally agree. i’ve been doing lots of searching fir Bash documentation myself, and finding lots of offline sites, dead projects, and outdated/missing information. it’s pretty annoying.

ramsey,
@ramsey@phpc.social avatar

@awoodsnet Also, the use of brackets, double brackets, and parentheses in conditional statements (along with = vs. ==) always trips me up. I know portability and POSIX compliance is part of the difference, but it’s hard to remember (and, again, difficult to find the information quickly).

awoodsnet,
@awoodsnet@phpc.social avatar

@ramsey I’ve heard of POSIX, and know that compliance can be required sometimes. TBH, i’ve never spent one second of scripting time thinking about it. However, it looks like Ive quite a bit of learning ahead of me, if that needs to be an option.

ramsey,
@ramsey@phpc.social avatar

@awoodsnet POSIX is a standard for compatibility across systems. Some Bash features or programs used are defined by POSIX, so using them means you can be certain they’ll run on any POSIX system. Lots of Unix systems (including macOS), many Linux distributions, and Windows (with certain add-ons) are POSIX compliant.

There are Bash features that aren’t POSIX compliant and aren’t guaranteed to work on all systems.

awoodsnet,
@awoodsnet@phpc.social avatar

@ramsey i’ll have to do some research determine how much effort POSIX would be to implement, and if i want to care about it. It’s possible that for what I’m considering for development — maybe it won’t be a big deal.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • Bash
  • DreamBathrooms
  • magazineikmin
  • ethstaker
  • InstantRegret
  • tacticalgear
  • rosin
  • love
  • Youngstown
  • slotface
  • ngwrru68w68
  • kavyap
  • cubers
  • thenastyranch
  • mdbf
  • megavids
  • cisconetworking
  • GTA5RPClips
  • modclub
  • khanakhh
  • everett
  • Leos
  • osvaldo12
  • normalnudes
  • tester
  • Durango
  • anitta
  • provamag3
  • JUstTest
  • All magazines