BASH: option argument with '=' is mistaken as variable assignment
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Slackware, Debian, FreeBSD, Arch Linux, Ubuntu, Kubuntu, CentOS, OS X
Posts: 21
Rep:
BASH: option argument with '=' is mistaken as variable assignment
This is more a bash syntax question.
I want the variable calender_month to have the value of the this:
Code:
date +%m --date='-3 month' | sed -e 's/000$//' -e 's/^0//'
In my bash script, I am doing this:
Code:
calender_month=$(date +%m --date='-3 month' | sed -e 's/000$//' -e 's/^0//')
^ This is not working. My guess is that...
Code:
calender_month=$(date +%m --date='-3 month' | sed -e 's/000$//' -e 's/^0//')
...is being seen by bash as assigning a value to some variable date.
What do I need to do so that calendar_month contains what I want?
Thanks!
P.s., all the search results online for "option argument is mistaken as variable assignment" yeld results on how to parse option arguments in bash using getopt, etc.
Distribution: Slackware, Debian, FreeBSD, Arch Linux, Ubuntu, Kubuntu, CentOS, OS X
Posts: 21
Original Poster
Rep:
I should have thought of using backticks. Unfortunatley the result is still the same. Also, the sed is supposed to remove the zero from the stdout from date. Were you referring to that, or something else?
Run the script with the "-x" option so that you can see what it is doing. You probably have some sort of mismatched quotes or brackets in one of the previous lines of the script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.