: "${DOTFILES_PATH:=$HOME/.dotfiles}"
Which will use $DOTFILES_PATH value if it's set, otherwise it's going to be $HOME/.dotfilesA shell colon does nothing. Use it anyway
71–80 of 191 posts
Re: A shell colon does nothing. Use it anyway
#72I have an alias[1] for that which I call a quick interactive rebase:
riq = -c sequence.editor=: rebase --interactive
[1]: https://github.com/fphilipe/dotfiles/blob/94f2ff70bade070694...Re: A shell colon does nothing. Use it anyway
#73 [ -z "$1" ] && { echo "missing argument, aborting." 1>&2; exit 1 }Re: A shell colon does nothing. Use it anyway
#74Some of the examples here are interesting, but they show parameter substitution more than colon itself: https://tldp.org/LDP/abs/html/parameter-substitution.html
In small scopes, I tend to inline the `:?` validation inside the arg of the command. `echo "${1:? first param required}"`
Another usecase is to use colon in the body of a while loop, while doing work in the condition of the loop.
while rlwrap -o -S'>> ' tr a-z A-Z ; do :; done
Gives you the "do X while it succeeds. stop when it returns non-0" semantics.I've also written about this and other bash tricks over the years in https://github.com/kidd/scripting-field-guide/blob/master/bo.... You might like them :)
Re: A shell colon does nothing. Use it anyway
#75Btw, can the sequence :? be called "reverse Elvis" ?
Re: A shell colon does nothing. Use it anyway
#76What if there was a less cryptic way to have mandatory arguments, something harder to get wrong, like param( [parameter(mandatory)] $name ) "Hello, $name!" And then: $ ./script.ps1 Dave Hello, Dave! $ ./script.ps1 -name Dave Hello, Dave! $ ./script.ps1 cmdlet script.ps1 at command pipeline position 1 Supply values for the following parameters: name: Or non interactively: $ pwsh -nonint ./script.ps1 script.ps1: Cannot…
PowerShell is a bad choice for the system shell because it's too complex. I'm not trying to justify all the quirks of Unix Shell, but minimalism is a very important feature of such a tool. Another important feature of a tool like this is the ability to tolerate errors: I can't imagine a Linux today that would be able to even boot if the shell was extra pedantic about errors. A lot of mostly irrelevant things routinel…
Re: A shell colon does nothing. Use it anyway
#77 1. Everyone wants the colon.
2. Larry gets the colon.Re: A shell colon does nothing. Use it anyway
#78I use the colon as EDITOR with Git when I want to do an interactive rebase combined with auto squash without having to edit the todo list. I have an alias[1] for that which I call a quick interactive rebase: riq = -c sequence.editor=: rebase --interactive [1]: https://github.com/fphilipe/dotfiles/blob/94f2ff70bade070694...
Re: A shell colon does nothing. Use it anyway
#79Why take a perfectly readable if-statement and turn it into something, 99.9% of people would need to lookup. Concise != better. You can make it one line with: [ -z "$1" ] && { echo "missing argument, aborting." 1>&2; exit 1 }
Re: A shell colon does nothing. Use it anyway
#80Well that's exciting. I learned a lot of uses for ":" today. However, the only one I already knew... if some-command; then : # command required else echo "command failed" fi I used to do that until I learned of if ! some-command; then echo "command failed" fi It's in the POSIX standard so it's not just a bashism: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V... > If the pipeline does not begin with the…