If I execute this line within a function of my bash script, it runs successfully:
function myFnc(){
...
variable1=$(date -d 2021-01-01 +%W)
...
}
But if I pass '2021' as input argument by running
myBash.sh '2021'
I get an error "date: date not valid #-01-01" if I replace the year with the corresponding variable:
function myFnc(){
...
variable1=$(date -d $1-01-01 +%W)
...
}
Also using quotes does not help:
function myFnc(){
...
variable1=$(date -d "$1-01-01" +%W)
...
}
Any idea on how to solve it? Thanks in advance!