ent dir
./real_bash_source_dir_test
You can see it is able to source its library relative to its real
installed path and it works regardless of if called from a symbolic link
or directly from its installed dir.
--
Léa Gris
ame answer in both cases:
./tests/real_bash_source_dir_test
./real_bash_source_dir_test
--
Léa Gris
se put the JSON text string as the value.
But possibly people are overusing Bash and shell for things that it was
not designed for. In a lot of case, more general purpose scripting
language are available to a wide range of systems.
When your favorite tool is a hammer, problems tend to look
c analysis tools like Shellcheck which might be expanded
to ware of such incompatible flags but that's it.
--
Léa Gris
e actual numbers vary a lot depending on request accuracy. Because
there is no Regex replacement for a shell language parser; it cannot
match all syntactically valid use cases, even with a carefully crafted
Regex.
--
Léa Gris
-effects?
--
Léa Gris
s with
attributes is indeterminate"), which might be an appropriate clarification?
--
Léa Gris
mpty value (same as referencing an associative
array without a [key].
export upper; export lower # export with converted value
export nameref # export with value of the referee
This means that the export command would expand the variable value
before exporting, but the declare, local and typeset statements would
error if flags are incompatible with -x export.
--
Léa Gris
Le 16/02/2022 à 13:43, Greg Wooledge écrivait :
text=$(cat /tmp/foo.txt; printf x)
text=${text%x}
or read -r -d '' text
*)
exit 1
esac
}
}
The bug is in your code.
https://shellcheck.net/ static analysis for shell scripts can help you
spot such syntax errors.
--
Léa Gris
ty state of a nameref is
only obtained with an initial `declare -n ref`.
There is no way to later clear or assign an empty string to a nameref
unless destroying and recreating the nameref with:
unset -n ref
declare -n ref
--
Léa Gris
if a bash script is able to be abused, it is not bash's fault,
neither the script's fault, but the system's security policies granting
those privileges to the user running the script.
--
Léa Gris
enuine human
errors, this is a red flag to avoid shell scripts and find a more
suitable language/tool for this task.
--
Léa Gris
ld be:
test "${USER_INPUT@Q}"
But it is not backward-compatible with older bash versions.
Alternatively:
declare -p USER_INPUT >/dev/null 2>&1
will work with much older bash versions
Any other way witch are less bulky and or more backward compatible?
--
Léa Gris
declare +i -A assoc=([yeet]=hello)
declare -p assoc
declare -A assoc=([yeet]="0" )
--
Léa Gris
Le 02/10/2021 à 18:45, Greg Wooledge écrivait :
On Sat, Oct 02, 2021 at 06:06:32PM +0200, Léa Gris wrote:
Better illustrated how newlines are discarded:
$ sudo bash -c 'echo hello
echo world'
hello
world
$ sudo -i bash -c 'echo hello
echo world'
helloecho world
OK, that's news to me
Le 02/10/2021 à 15:09, Greg Wooledge écrivait :
On Sat, Oct 02, 2021 at 01:41:35PM +0200, Léa Gris wrote:
$ declare -f hello
hello ()
{
echo 'hello';
echo 'world'
}
The issue is that in some circumstances, newline characters may be handled
as space, making the function declaration
for both
the output of declare -p and declare -f
--
Léa Gris
# shellcheck broken nameref usage check
arr=("${BASH_REMATCH[@]:1}")
}
--
Léa Gris
Le 24/08/2021 à 14:06, Greg Wooledge écrivait :
unicorn:~$ f6() { local i n=${#1} arr; for ((i=0; i
See my featured version to also capture space and newlines:
https://stackoverflow.com/a/68907322/7939871
--
Léa Gris
extglob
# Split string characters into array
IFS=' ' read -r -a array <<<"${n//?()/ }"
# Debug print array
declare -p array
--
Léa Gris
az" 3 "qux"
"${arr[@]@a}" expands into 4 argumsnts:
1. a
2. a
3. a
4. a
Now @K would have been useful if it expanded into individual arguments
for each entry rather than an eval expression.
The @A suffers from the same weirdness expanding into an eval expression
that actually duplicates the feature from declare -p.
The @a expands the attribute from the container array for each element,
which is as strange, because all array elements don't have attributes of
their own.
--
Léa Gris
Le 21/08/2021 à 00:06, Chet Ramey écrivait :
On 8/19/21 6:37 AM, Léa Gris wrote:
#!/usr/bin/env bash
declare -A assoc=(
[P]=piano
[TB]='foldable table'
['CH AIR']=chair
)
options=("${assoc[@]@K}")
The best way to clone an associative array is:
declare -A options
ev
Le 19/08/2021 à 16:41, Eli Schwartz écrivait :
On 8/19/21 9:41 AM, Léa Gris wrote:
The error occurs, one would imagine, during the "convert string to
float" stage, after parsing argv or forking to bc or whatever, but
*before* passing it as an argument to printf(3). Here, bash is
t, but the argument format's
decimal separator is that of the system's locale.
Imagine if C++ or Java had methods with different signature depending on
system locale. You would scream fool. But for Bash, it was decided it
was all fine.
--
Léa Gris
Han
(LC_NUMERIC=C; echo "$EPOCHREALTIME")
It will use a dot
--
Léa Gris
into arguments and not expand quotes
as string content.
This would have made the @K expansion usable for dialog.
Currently the associative array's key values pairs need be added to the
options array in a for loop as:
options=()
for k in "${!assoc[@]}"; do
options+=("$k" "${assoc[$k]}")
done
--
Léa Gris
ng the value with statement
within the loop.
Obviously it would fit equally well with associative arrays.
--
Léa Gris
; \"me\" )"
declare -g "$variable"'=( "world" "me" )'
Be cautious with dynamic declare statements, because it is as insecure
as eval. It will execute statements contained in variables.
--
Léa Gris
a.sh:7
msgid "String %1$q has %2$d characters\n"
msgstr "%2$d Zeichen lang ist die Zeichenkette %1$q\n"
```
In default English, the output would be:
```none
String Hello\ World\! has 12 characters
```
In German, the output would be:
```none
11 Zeichen lang ist die Zeichenkette Hallo\ Welt\!
```
--
Léa Gris
rintf format string
context to maintain backward compatibility.
--
Léa Gris
Le 15/07/2021 à 21:23, Greg Wooledge écrivait :
On Thu, Jul 15, 2021 at 05:28:04PM +0200, Léa Gris wrote:
Le 15/07/2021 à 16:36, Gabríel Arthúr Pétursson écrivait :
Hi all,
Executing the following results in a fierce crash:
$ bash -c '{0..255}.{0..255}.{0..255}.{0..255}'
Brace
c=0; c<=255; c++)); do
for ((d=0; d<=255; d++)); do
printf '%d.%d.%d.%d\n' "$a" "$b" "$c" "$d"
done
done
done
done
--
Léa Gris
and everyone has fought each-other.
Then they will vanish and destroy other community, other history.
--
Léa Gris
ion,
^^^
French "son" (his) is male because "répertoire" (directory) is male in
French. User character's gender is not even mentioned.
--
Léa Gris
from cancel
culture tenants.
With all your clever carefulness in patching this. It remains a rewrite
of history motivated by political reasons from a lobbying group of
people spreading their damaging delusions everywhere.
--
Léa Gris
people's
grammar, "they" is a plural pronoun.
--
Léa Gris
ll heavily
hot debated and politically loaded changes into technical projects like
Bash.
--
Léa Gris
declare -i last_index="42"
It would be convenient to be able to index directly with this syntax:
declare -i first_index=${!array[@]:0:1}
declare -i last_index=${!array{@}: -1:1}
--
Léa Gris
expect being on every systems, even older
and no longer supported ones?
--
Léa Gris
/59e1b7e72462024b278652696f375e71
There is no need for bash specific features, although coproc and other
fancynesses can help, these lack portability.
--
Léa Gris
ocarray=([$'1\E[G\E[K2']=$'and \E esc' [$'new \n
line']=$'1\E[G\E[K2' )
declare -i intvar=42
declare -ai intarray=([0]="-42" [1]="666" [2]="555")
declare -Ai intassoc=([$'1\E[G\E[K2']="456" [foo]="123" [bar]="789" )
declare -i nameref=42
--
Léa Gris
OpenPGP_signature
Description: OpenPGP digital signature
the produced
declare statement just works as-is. It is not user friendly but code
friendly and compact if you use the declare -p foo bar baz >savedvars.sh
for later include savedvars.sh
--
Léa Gris
OpenPGP_signature
Description: OpenPGP digital signature
t;
printf '%s -> %s\n' "$key" "$value"
done
I'd love there would be more convergence when this is possible.
--
Léa Gris
OpenPGP_signature
Description: OpenPGP digital signature
into the array.
Works, if you declare your associative array with A and i flags:
(
LANG=C
unset var assoc
var=\'\]
declare -Ai assoc
assoc[$var]=1
assoc[$var]+=1
((assoc['$var']++))
typeset -p assoc
)
Output:
declare -Ai assoc=(["']"]="3" )
--
Léa Gris
, after: r=2 || exit 2
still there with $?=1, after: if ! r='hello'; then exit; fi
declare -r r
--
Léa Gris
)
bash: ']: syntax error: operand expected (error token is "']")
but:
$ (LANG=C; unset var assoc; var=\'\]; declare -A assoc; assoc[$var]=hello;
typeset -p assoc)
declare -A assoc=(["']"]="hello" )
--
Léa Gris
. Kind of annoying, sure, but not a bug.
https://mywiki.wooledge.org/BashPitfalls#local_var.3D.24.28cmd.29
vq
Or this https://github.com/koalaman/shellcheck/wiki/SC2155
Nice helping shell linter would have warned of this pitfall.
--
Léa Gris
(formerly Ctrl + Z) that is unlikely to be part of a legit string:
a=$(printf $'hello\n\n\n\32'); a=${a%$'\32'}; declare -p a
--
Léa Gris
sh feature is not an
option anyway, and sometimes, yes eval will help.
--
Léa Gris
Le 22/01/2021 à 19:18, Léa Gris écrivait :
Now replace the the () with {}, replace the implicit temporary fifo by
and implicit temporary file; then have the same feature but without
spawning a sub-shell.
Instead of:
tempfile=$(mktemp) || exit 1
trap 'rm -f "$tempfile"' EXIT
; then have the same feature but without
spawning a sub-shell.
--
Léa Gris
a temporary file in /tmp or /dev/shm
rather-than a temporary named fifo as with < <(:).
--
Léa Gris
Le 20/01/2021 à 13:51, Andreas Schwab écrivait :
But that's not the value of the parameter.
It is not, since at this point, the parameter has no value, the
expansion expands the argument's value after ;= which is uppercase X here.
--
Léa Gris
The fact that an expansion also assign a value is a questionable design
choice though.
If I had to use this I would just silence the expansion as an argument
to the dummy true or : command
: ${a:=X}
Is this a bug or am I missing something here?
Then likely not.
--
Léa Gris
ne of them will output a null byte.
The only way to output a null byte with shell built-in is:
printf '\0'
or non portable: echo -ne '\0'
This is because `\0' is not a null byte or a nulll string but
interpreted internally to the command to print a null byte.
--
Léa Gris
Le 14/01/2021 à 16:15, Chet Ramey écrivait :
On 1/13/21 4:40 PM, Léa Gris wrote:
Le 13/01/2021 à 22:13, Chet Ramey écrivait :
The `-i' forces arithmetic evaluation, which makes this expand to the
equivalent of `declare -n b=1'. That's an invalid name for a nameref,
which you'd see if you used
:
declare -ai a=([0]="4")
declare -in b="a[0]"
declare -ai a=([0]="10")
declare -in b="a[0]"
I set the integer attribute to the nameref b after it has been assigned
the "a[0]" string, so it keeps its string nameref value but is now also
considered as an integer value.
--
Léa Gris
unset a b
declare -ai a=(1)
declare -in b="a[0]"
declare -p a b
declare -ai a=([0]="1")
declare -in b="a[0]"
b+=1
declare -p a
declare -ai a=([0]="3")
b+=1
declare -p a
declare -ai a=([0]="7")
b+=0
declare -p a
declare -ai a=([0]="14")
--
Léa Gris
Le 11/01/2021 à 15:42, Léa Gris écrivait :
Declare an integer associative array instead:
echo "$BASH_VERSION"
5.0.17(1)-release
declare -Ai aa
x='y[$(date >&2)0]'
aa[$x]=1
declare -p aa
declare -Ai aa=(["y[\$(date >&2)0]"]="1" )
aa[$x]+=1
decl
Declare an integer associative array instead:
echo "$BASH_VERSION"
5.0.17(1)-release
declare -Ai aa
x='y[$(date >&2)0]'
aa[$x]=1
declare -p aa
declare -Ai aa=(["y[\$(date >&2)0]"]="1" )
aa[$x]+=1
declare -p aa
declare -Ai aa=(["y[\$(date >&2)0]"]="2" )
--
Léa Gris
Le 08/01/2021 à 15:26, Chet Ramey écrivait :
On 1/8/21 8:45 AM, Léa Gris wrote:
Just curious why it accepts a + before =
Try it with a variable that already has a value.
OMG I feel stupid now!
--
Léa Gris
Just curious why it accepts a + before =
unset a; declare a+=hello; typeset -p a
bash, version 5.0.17(1)-release wrote:
> declare -- a="hello"
--
Léa Gris
Le 04/01/2021 à 14:14, Greg Wooledge écrivait :
It should be noted that $(
var=$(ending the last line because it exactly a sub-shell shot syntax for
var=$(cat file). Sub-shell $(commands list) output is always trimmed.
--
Léa Gris
or move files.
--
Léa Gris
a sub-shell background
command, then shame on them.
--
Léa Gris
ces,
Bash is a very bad choice. If you want to stay with scripting, as you
already mentioned using Python; Python is a way better choice for
dealing with the features and requirements you describes.
--
Léa Gris
Le 17/12/2020 à 17:58, Léa Gris écrivait :
Maybe (it is clearly open to discussion), the associative array mapping
could be allowed to:
- skip blank/comment only lines (1)
- allow key without value
- optionally trim trailing comment (1)
Forgot about Bash built-in Regex engine:
- allow using
Le 17/12/2020 à 17:35, Chet Ramey écrivait :
One problem I see with it is that it assumes the introduction of word
splitting into mapfile, with the burden on the user to ensure that there
are exactly two resultant fields.
It is just meant to be a replacement to looping on:
IFS= read -r -d k
Shorty shim:
! { mapfile -A _/dev/null&&{ mapfile(){ local k v
d=$'\n';local -n A=${*: -1:1};[ ${*: -2:1} = -A ]&&{ [ ${*:1:1} = -d
]&=${*:2:1};while read -rd "$d" k v||[[ -n $k && -n $v ]];do
A[$k]=$v;done;:;}||command mapfile "$@";};}
--
Léa Gris
{*: -2:1} = -A ]] && {
[[ ${*:1:1} = -d ]] && d=${*:2:1}
while read -r -d "$d" k v || [[ -n $k && -n $v ]]
do A[$k]=$v
done
true
} || command mapfile "$@"
}
}
Example usage:
. mapfile_assoc_shim.bash
IFS='=' mapfile -d '' -A assoc_null < <(kv_null_stream)
--
Léa Gris
assoc_null
Expected output:
declare -A assoc_cr=([key2]="value=2" [key1]="value1" ["key 3"]="value3" )
declare -A assoc_null=([key2]="value=2" [key1]="value1" [$'key\n3']="value3" )
--
Léa Gris
nd accept assignment,
which is probably conformant to POSIX shell specifications.
--
Léa Gris
quot; )
What would have been so useful is expanding mapfile to associative arrays:
key${IFS}value
declare -A assoc
IFS='= ' mapfile -t assoc <declare -A assoc(["key1"]="value1" ["key2"]="value2" ["key3"]=$'{\n
"otherkey": "othervalue"\n}'
--
Léa Gris
t does not split a key variable:
foo='1 2'
declare -A bar=([$foo]=3 )
Or double square bracket tests:
foo='1 2'
[[ $foo == '1 2' ]]
Did you try with?:
# possibly originating read -a or mapfile
declare -a foo=(1 2 )
# Declare associative array from key value array above
declare -A assoc=("${foo[@]}" 3)
--
Léa Gris
typeset -p x
> declare -- x="42624"
unset x; declare -i x; ((x = 42)); x+=624; typeset -p x
> declare -i x="666"
--
Léa Gris
Anyone to look why this is no longer connected to the bug-bash@gnu.org ML?
--
Lea Gris
straight
exit without any cleanup or fallback.
This feature deserves a bold disclaimer to think twice before using it
rather than explicit error handing.
--
Léa Gris
craft so long to lerne.'' - Chaucer
Chet Ramey, ITS, CWRUaddress@hiddenhttp://cnswww.cns.cwru.edu/~chet/
--
Léa Gris
cument in usage:, add to builtin help.
--
Léa Gris
OpenPGP_0x70946F168078ED52.asc
Description: application/pgp-keys
OpenPGP_signature
Description: OpenPGP digital signature
man bash.1
> When callback is evaluated, it is supplied the index of the next
> array element to be assigned and the line to be assigned to that
> element as additional arguments. callback is evaluated after the
> line is read but before the array element is assigned.
I can not find real-life
Le 12/12/2019 à 20:13, Chet Ramey écrivait :
>> # Empty array declared without parenthesis
>> unset myArr
>> declare -a myArr
>> typeset -p myArr
>> echo "${#myArr[@]}"
>
> This is an unset variable with the array attribute; you have not assigned a
> value.
>> # Empty array declared without
rr
declare -a myArr=()
typeset -p myArr
echo "${#myArr[@]}"
output:
declare -a myArr=()
0
What is the reason for having different states for empty arrays?
--
Lea Gris
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
Hello,
Depending on how an empty array is declared, it is not stored with the
same state.
# Empty array declared without parenthesis
unset myArr
declare -a myArr
typeset -p myArr
echo "${#myArr[@]}"
output:
declare -a myArr
0
# Empty array declared without parenthesis
unset myArr
declare -a
uot;]="second");
a+=(["three"]="third"); a+=(["four"]="last"); typeset -p a
Is there a way to control the order of entries in an associative array?
What rules applies to the order of entries?
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
;$a $b":\n=> '
printf $"a='%s' b='%s' c='%s'\\n" "$a" "$b" "$c"
knip code end
Output:
bash ./test_declare.sh
Explicit declarations statements:
typeset -i a=2 b=$a c="$((a - 1))":
=> a=2 b=0 c=-1
declare a=hello b=world c="
: declare: not found [Aucun fichier ou dossier de ce type]
a='' b='' c=''
Implicit declarations statements:
a=2 b=$a c="$((a - 1))":
=> a=2 b=2 c=1
a=hello b=world c="$a $b":
=> a='hello' b='world' c='hello world'
ksh93 resolves explicit back-references with typeset.
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
;${_v} value2")
declare -p foo
Still safer than eval for an extra intermediary assignment.
And allow you to insert the old value of ${foo=["key"]} anywhere
in-between. The += string concatenation would not work in this case.
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
Le 12/07/2019 à 21:16, Chet Ramey écrivait :
On 7/12/19 12:46 PM, Léa Gris wrote:
Le 09/07/2019 à 22:02, Chet Ramey écrivait :
These are up to the system's strtol/strtod. I don't know of too many
strtol implementations that use the thousands separator and numeric
grouping.
Chet and you
the incentives behind this library/stand-alone
command, that may shed some light on how the Bash's printf
implementation of the %f format can be an issue.
Be glad if it can helps in some way.
Do what the F** you want with it :)
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
s_sep
LC_NUMERIC
thousands_sep=" "
$ printf '%d\n' '1 000 000'
bash: printf: 1 000 000: nombre non valable
1
--
Léa Gris
signature.asc
Description: OpenPGP digital signature
91 matches
Mail list logo