LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-14-2013, 06:50 PM   #1
muahahaha9001
LQ Newbie
 
Registered: Sep 2012
Location: Northern Virginia, USA
Distribution: Slackware, Debian, FreeBSD, Arch Linux, Ubuntu, Kubuntu, CentOS, OS X
Posts: 21

Rep: Reputation: 0
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.
 
Old 10-14-2013, 07:14 PM   #2
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
Quote:
calender_month=`date +%m --date='-3 month' | sed -e 's/000$//' -e 's/^0//'`
maybe, it removes the zero though, hm
 
Old 10-14-2013, 07:30 PM   #3
muahahaha9001
LQ Newbie
 
Registered: Sep 2012
Location: Northern Virginia, USA
Distribution: Slackware, Debian, FreeBSD, Arch Linux, Ubuntu, Kubuntu, CentOS, OS X
Posts: 21

Original Poster
Rep: Reputation: 0
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?
 
Old 10-14-2013, 07:40 PM   #4
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 174Reputation: 174
Quote:
Also, the sed is supposed to remove the zero from the stdout from date. Were you referring to that, or something else?
oh, i didn't see that you WANT to remove zero,..


however on my ubuntu

Quote:
calender_month=`date +%m --date='-3 month' | sed -e 's/000$//' -e 's/^0//'`
echo $calender_month
gives output
Quote:
7
isn't that what are you looking for?
 
Old 10-14-2013, 07:52 PM   #5
muahahaha9001
LQ Newbie
 
Registered: Sep 2012
Location: Northern Virginia, USA
Distribution: Slackware, Debian, FreeBSD, Arch Linux, Ubuntu, Kubuntu, CentOS, OS X
Posts: 21

Original Poster
Rep: Reputation: 0
Wow, it does the same on my CentOS! Both at a bash prompt and in a script.

You helped me figure that part out, but I still can't get this to work in the script I'm writing. I get this type of error:

Code:
cut: invalid byte, character or field list
Try `cut --help' for more information.
I'm difinitley not calling cut here. Not sure whats happening.

Last edited by muahahaha9001; 10-14-2013 at 08:17 PM.
 
Old 10-14-2013, 08:34 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,770

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Question on variable naming and assignment... ${manintheyellowhat} Linux - Newbie 6 07-26-2010 07:41 PM
Variable assignment in Lisp. zaxonus Programming 2 03-18-2010 06:10 AM
[SOLVED] [bash] option followed by argument list hashbang#! Programming 5 02-08-2010 02:18 PM
[SOLVED] [BASH] variable assignment help RaptorX Programming 2 08-30-2009 10:28 AM
trivial: bash, local variable assignment agrestic Linux - Newbie 3 01-27-2009 11:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration