You are not logged in.

#1 2014-05-02 12:26:00

tylerpnn
Member
Registered: 2014-03-06
Posts: 20

Problem with dzen2 and bash

I'm having a problem piping the date to dzen2 using the date command in a while loop in bash.

In my startup script I have this line to start the panel and the script to pipe the info:

statusbar | dzen2 -h $PANEL_HEIGHT -dock -ta l -title-name panel -fn $FONT -fg $PANEL_TEXT_LIGHT -bg $PANEL_BG &

and then the statusbar script looks like this:

while true ; do
	echo "$(date +%I:%M %p)"
	sleep 1
done

That isn't the complete statusbar script, but i've identified the date command as the problem. For whatever reason, when the date command is in the loop, there is no output to the panel, and if I monitor my system resources I can see that my computer's memory is getting used up extremely quickly. It seems like it spawning a bunch of instances of the script. I'm not extremely experienced with linux, and definitely not with bash, so I have absolutely no clue whats going on here.

Offline

#2 2014-05-02 12:29:10

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: Problem with dzen2 and bash

$ echo "$(date +%I:%M %p)"
date: extra operand ‘%p’
Try 'date --help' for more information.

Edit: since you're basically saying you're a newbie (and this also probably fits better in the Newbie Corner), I'll add that you should put the formatting string in (single) quotes to turn it into a single argument.

Last edited by Raynman (2014-05-02 12:33:17)

Offline

#3 2014-05-02 12:33:05

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Problem with dzen2 and bash

The date format needs to be one parameter. Try wrapping it with '...', eg:

echo "$(date '+%I:%M %p')"

Incidentally, it often helps to run a command manually, outside the full script/pipeline, to see if there are any issues.
Either that and/or redirect the error output so you can see it: http://mywiki.wooledge.org/BashGuide/InputAndOutput

Last edited by skanky (2014-05-02 12:35:28)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#4 2014-05-02 12:55:29

tylerpnn
Member
Registered: 2014-03-06
Posts: 20

Re: Problem with dzen2 and bash

Raynman wrote:
$ echo "$(date +%I:%M %p)"
date: extra operand ‘%p’
Try 'date --help' for more information.

Edit: since you're basically saying you're a newbie (and this also probably fits better in the Newbie Corner), I'll add that you should put the formatting string in (single) quotes to turn it into a single argument.

I'm not saying I'm a newbie at all. The issue occurs even without any parameters to the date command.

Offline

#5 2014-05-02 13:46:06

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Problem with dzen2 and bash

This works fine for me:

while true; do echo $(date); sleep 1; done | dzen2

"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

Board footer

Powered by FluxBB