Il y a autant de générosité à recevoir qu'à donner- Julien Green
Roughly translated to
There is only as much generosity to receive as there is to give.
Il y a autant de générosité à recevoir qu'à donner- Julien Green
There is only as much generosity to receive as there is to give.
file=foo_1.23-1.dsc echo ${file:0:1}/${file%%_*}/$file
file=foo_1.23-1.dsc echo ${file%${file#?}}/${file%%_*}/$file
file=libbar_3.2-1.dsc if [ lib = "${file:0:3}" ]; then length=4 else length=1 fi # Note the use of a dynamic length: echo ${file:0:$length}/${file%%_*}/$file
file=libbar_3.2-1.dsc case "$file" in lib*) length=4 ;; *) length=1 ;; esac length_pattern= while [ 0 -lt $length ]; do length_pattern="${length_pattern}?" length=$(($length-1)) done echo ${file%${file#$length_pattern}}/${file%%_*}/$file
genpattern() { local pat= local i="${1:-0}" while [ 0 -lt $i ]; do pat="${pat}?" i=$(($i-1)) done printf %s "$pat" } substr() { local str="${1:-}" local offset="${2:-0}" local length="${3:-0}" if [ 0 -lt $offset ]; then str="${str#$(genpattern $offset)}" length="$((${#str} - $length))" fi printf %s "${str%${str#$(genpattern $length)}}" }
var=foo # Replace the bashism ${var:1} with: echo ${var#?}
var="portable code" # Replace the bashism ${var:3:5} with the following code # Offset is 3, so we use three ? (interrogation) characters: part=${var#???} # Length is 5, so we use five ? characters: echo ${part%${part#?????}}
$ dash -c ' method=sed # some condition or user setting ends up making: method=true # later: foo=bar $method echo foo: $foo' foo:To (redacted for brevity):
$ dash -c ' method=: foo=bar $method echo foo: $foo' foo: bar
set -e. With that option set at the moment of calling return outside of the allowed scopes, bash will abort the execution, as desired.