Score:0

"bad variable name : read:" in my script

pn flag

here is my script -

#!/bin/bash

echo "Enter date (YYYY-MM-DD) : "
read userdate

is_valid = date "+%Y-%m-%d" -d $userdate > /dev/null  2>&1

echo $is_valid

while I am trying to execute the script, its asking for "Enter date (YYYY-MM-DD) :", while I am entering date, its giving : bad variable name 4: read: userdate and 7: Syntax error: Bad fd number

here is my system configuration detail -

Operating System: Ubuntu 20.04.5 LTS
        Kernel: Linux 5.4.0-99-generic
      Architecture: x86-64

Please help me to solve this, here I am just asking to get date from user input and checking that date is valid or not.

Thanks

Artur Meinild avatar
vn flag
To solve the line encoding easily, create a new blank file on Linux, and copy and paste the code from your question. It will then have correct line breaks.
hr flag
The syntax of Line 6 is also invalid - if you want to assign the exit status, you will need to use something like `date "+%Y-%m-%d" -d "$userdate" > /dev/null 2>&1; is_valid=$?`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.