#need some help with the bash script
10 messages · Page 1 of 1 (latest)
That would imply there is an issue either with the array or with the support of that specific function
Have you tried looking into an alternative to the array?
Such as "sleep" for example
Additionally, you said this:
If I use single quotes, like this: rcon -c $RCONYAML 'servermsg "${arr_msg[$1]}"' &>/dev/null, then ${arr_msg[$1]} is output to the screen and chat.
Why not just use the single quotes if it works right?
To tell you the truth, I simplified the script a bit in the initial question, which didn't go well. The function looks like this:
func_notification() {
rcon -c $RCONYAML "servermsg ${arr_msg[$1]}" &>/dev/null
echo "${arr_not[$1]}" >&2
sleep ${arr_sec[$1]}
}
and there's also an array
arr_not=(
"first notification in console"
"second notification in console"
)
so the function, when executed, outputs an additional notification to the console for me personally ( echo "${arr_not[$1]}" >&2 ). This command works correctly, and it may not contain "" ( echo ${arr_not[$1]} >&2 ) (this is just a recommendation to specify variables in bash in double quotes, which I follow). The problem is that in the case of rcon servermsg and text must be enclosed in double quotes (rcon -c $RCONYAML "servermsg text"), otherwise it doesn't work. Can we hope that the servermsg command will work without the ""? Because the rcon -c $configfile quit command does not require qiut to be enclosed in double quotes.
I could get rid of the arrays and the for loop, but firstly that seems less correct, and secondly, since I'm going to let other people use my linux server management utility, changing text in an array seems easier than in a number of directly written commands. The array can be put in a separate file.
because in bash, if something is enclosed in single quotes '_', the reference to the $VARIABLE will not be processed, text "$VARIABLE" will be typed instead
Could you not put the separrate commands in a separate file and call those files? Since the issue looks to be due to the array usage specifically
I still have the original problem, but I would like to write a different topic, with simpler code and a slightly differently formulated question.