When the first element of an array is '-n' or '-e', has strange behavior, looks like some times the first element is missing.
My script test.sh
:
#!/bin/bash
declare -a arrayP=('-p' 'text')
echo "arrayP"
echo ${arrayP[@]}
echo "${arrayP[@]}"
echo "'${arrayP[@]}'"
echo " ${arrayP[@]}"
echo ""
declare -a arrayN=('-n' 'text')
echo "arrayN"
echo ${arrayN[@]}
echo "${arrayN[@]}"
echo "'${arrayN[@]}'"
echo " ${arrayN[@]}"
echo ""
declare -a arrayE=('-e' 'text')
echo "arrayE"
echo ${arrayE[@]}
echo "${arrayE[@]}"
echo "'${arrayE[@]}'"
echo " ${arrayE[@]}"
Execution results:
root@host:~# ./test.sh
arrayP:
-p text
-p text
'-p text'
-p text
arrayN:
texttext'-n text'
-n text
arrayE:
text
text
'-e text'
-e text
root@host:~#
arrayP
works as expected, but arrayN
and arrayE
, each one behaves in different way.
I'm guessing -n
, -e
and probably others, have special meaning in some way, I cold not find any related information.
I'm using GNU bash, version 4.2.37(1)-release (x86_64-pc-linux-gnu)