Sysop.Fr
Cat├ęgories

apache

awk

bash

charmap

date

echo

encoding

find

grep

hexdump

irc

iso3166

ls

mysql

openssh

printf

python

read

sed

seq

smpp

sort

tar

ucp

Articles

bash - fonctions

1. Définition, appel et retour d'une fonction

function args_with_spaces() {
    local l_params_array=("$@")
    local i=0
    for (( i=0; i<${#l_params_array[@]}; i++ )); do
        echo "$i=${l_params_array[$i]}"
    done
    return 0
}

smscid=9105
db_query_begin=$( date +"%Y-%m-%d %H:%M" -d "15 minutes ago" )
db_query_end=$( date +"%Y-%m-%d %H:%M" -d "5 minutes ago" )

args_array=("${smscid}" "${db_query_begin}" "${db_query_end}")
args_with_spaces "${args_array[@]}"

root@ubuntu:~# ./bash_function.sh
0=9105
1=2021-09-16 15:54
2=2021-09-16 16:04