LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-13-2015, 01:44 PM   #1
like100ninjas
LQ Newbie
 
Registered: Apr 2015
Posts: 24

Rep: Reputation: Disabled
need some shell scripting help


edit: once again, trying to make this lemonbar script work. i fixed all the error messages, and the script runs. i think my problem might be that i'm testing `read -r line' in a subshell, so the script never really parses the lines i'm trying to read. just a hunch. anyone know how to fix this? or maybe something else is wrong.

edit again: i keep trying different things but no text shows up on the bar still. i've tried adding "print $line" underneath the while line and nothing shows up.

$HOME/etc/lemonbar/panel_bar
Code:
#!/usr/bin/zsh

source $HOME/etc/lemonbar/config

while [[ -n $( read -r line ) ]] {
  case $line {
    S*)
      panel_status="{F$panel_c7}${line#?}{F-}"
      ;;
    T*)
      panel_title="{F$panel_c7}${line#?}{F-}"
      ;;
    W*)
      panel_info=''
      panel_data=${=line}
      for i in ${panel_data}; {
        case ${panel_data[$i]} {
          OFU*)
            panel_info="$panel_info{F$panel_c2} {F-}"
            ;;
          o*)
            panel_info="$panel_info{F$panel_c7} {F-}"
            ;;
          f*)
            panel_info="$panel_info{F$panel_c8} %{F-}"
            ;;
          u*)
            panel_info="$panel_info%{F$panel_c3} %{F-}"
            ;;
        }
      } 
      ;;
  }   
  print "%{l}$panel_title%{c}$panel_info%{r}$panel_status"
}
$HOME/etc/lemonbar/panel
Code:
#!/usr/bin/zsh

source $HOME/etc/lemonbar/config

if [[ $(pgrep -cx panel) -gt 1 ]] {
    print -P "%F{1}the panel is running%f" >&2
    exit 1
}

if [[ -p $panel_fifo ]] { rm $panel_fifo }

mkfifo $panel_fifo

bspc control --subscribe > $panel_fifo &
xtitle -sf 'T%s' > $panel_fifo &
date '+S%I:%m %P' > $panel_fifo &

bspc config top_padding $panel_height

cat $panel_fifo | $HOME/etc/lemonbar/panel_bar | lemonbar -p \
    -n $panel_name \
    -g x$panel_height \
    -f $panel_font1 \
    -f $panel_font2 \
    -F $panel_fg \
    -B $panel_bg &
$HOME/etc/lemonbar/config
Code:
#!/usr/bin/zsh

typeset -gx panel_name=lemonbar panel_fifo=/tmp/panel-fifo panel_height=18 \
  panel_font1=ohsnap-9 panel_font2=ohsnap.icons-9

panel_fg='#ff839496'
panel_bg='#ff09090d'
panel_c1='#ff8c5760'
panel_c2='#ff7b8c58'
panel_c3='#ff8c6e43'
panel_c4='#ff58698c'
panel_c5='#ff7b5e7d'
panel_c6='#ff66808c'
panel_c7='#ff8c8b8b'
panel_c8='#ff545466'

Last edited by like100ninjas; 12-15-2015 at 10:47 PM. Reason: changed some stuff
 
Old 12-13-2015, 03:10 PM   #2
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,013

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
I never scripted in zsh, but for sure it would help if you posted the actual errors that you are getting.

That said, why are you scripting in zsh in the first place? As far as I know, the main reason why people choose zsh over bash is that it has features that make its use as an interactive shell more convenient.

If you write scripts, this advantage goes away, so what's the point? You can expect bash to be available on most modern *nix systems. You certainly can't expect that for zsh. If anything, you want to script in sh to get even more portable scripts than in bash, but zsh... makes no sense to me.

I might be missing something, though...
 
Old 12-13-2015, 03:16 PM   #3
like100ninjas
LQ Newbie
 
Registered: Apr 2015
Posts: 24

Original Poster
Rep: Reputation: Disabled
$ /home/satan/etc/lemonbar/panel_bar:35: parse error near `}'

i never really thought about it i guess. i started using zsh shortly after linux, and it never occurred to me to emulate bash all the time.
 
Old 12-14-2015, 07:27 AM   #4
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,013

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
Originally Posted by like100ninjas View Post
i never really thought about it i guess. i started using zsh shortly after linux, and it never occurred to me to emulate bash all the time.
Hmm, not sure what you mean by "emulating" but if you are going to invest time and effort into learning a shell scripting language I'd highly recommend you to actually make an informed choice on which one you learn.

It's perfectly valid to use a different shell for scripting than for your interactive shell.
 
Old 12-14-2015, 08:51 AM   #5
like100ninjas
LQ Newbie
 
Registered: Apr 2015
Posts: 24

Original Poster
Rep: Reputation: Disabled
yeah, it's pretty much just like bash. thanks for informing me. my hopes for anyone actually helping me weren't that high, anyway.
 
Old 12-14-2015, 09:14 AM   #6
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by like100ninjas View Post
yeah, it's pretty much just like bash.
Yeah, No.
Until you need a bash'ism like
Code:
while [[ $(( read -r line ) 2>&1 ) -le 0 ]]
See
Code:
man bash
CONDITIONAL EXPRESSIONS
 
Old 12-14-2015, 09:29 AM   #7
like100ninjas
LQ Newbie
 
Registered: Apr 2015
Posts: 24

Original Poster
Rep: Reputation: Disabled
the heck are you talking about? i don't really understand how that line is a bash'ism or what conditional expression would help. i tried some stuff out already. maybe you're saying that you know how to fix my problem, but it's so obvious that you're not telling. is that it? thanks for the bump, anyway.
 
Old 12-14-2015, 11:23 AM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,719

Rep: Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034Reputation: 3034
So I too am not much of a zsh guru, but are you sure about that while loop construct you created? I have never come across $(()) and had something in between the outer brackets?? What
error are you trying to redirect?
 
Old 12-14-2015, 11:27 AM   #9
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Yawnstown, Ohio
Distribution: Mojave
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I don't know zsh. Excuse me.

But this says a lot.
Zsh does not use readline, instead it uses its own and more powerful zle.

Last edited by Habitual; 12-14-2015 at 11:33 AM.
 
1 members found this post helpful.
Old 12-14-2015, 11:52 PM   #10
fu9ar
Member
 
Registered: Oct 2014
Location: Cyberinternetspace
Distribution: Slackware, mostly
Posts: 49

Rep: Reputation: 2
Look dude, he's saying that you should start by changing the first lines of your scripts to #!/bin/bash and then see what happens. It may also be beneficial to then post that output to the people helping you because then maybe some of the many people with the normal experience of using the standard tools available on every goddamn Linux system on the fucking planet can help you. Then, after ignoring their advice, you responded by getting progressively more huffy about it. If J. Hacker just fixes your shit, you learn nothing, which helps nobody.

Last edited by fu9ar; 12-14-2015 at 11:56 PM.
 
Old 12-15-2015, 12:20 AM   #11
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: Redhat/Centos, Ubuntu, Raspbian, Fedora, Alpine, Cirros, OpenSuse/SLES
Posts: 3,270

Rep: Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851Reputation: 851
Quote:
Originally Posted by fu9ar View Post
Look dude, he's saying that you should start by changing the first lines of your scripts to #!/bin/bash and then see what happens.
Given all the curly parentheses in the program, most certainly bash will choke and hurl a bunch of error messages at the unfortunate programmer. To help, we need somebody with zsh skills. Sorry, that's not me.
 
Old 12-15-2015, 04:18 PM   #12
fu9ar
Member
 
Registered: Oct 2014
Location: Cyberinternetspace
Distribution: Slackware, mostly
Posts: 49

Rep: Reputation: 2
That's my point. There are maybe like eight people in the universe writing zsh scripts. Ain't nobody got time for that.

The first step for you, like100ninjas, is to clean out the zsh and write normal bash scripts so that people can help you. You already know that subshells aren't working like you think they should. I've run into similar unexpected behavior with subshells in python scripts... So I rewrote them to work without using subshells and put a "figure out wtf subshells" task item on my long-term task list. I still haven't gotten to it because I've had better things to do. You are doing it wrong and you need to go back to the drawing board!

edit: you're right joe2k, I took it down a notch.

Last edited by fu9ar; 12-15-2015 at 05:29 PM.
 
Old 12-15-2015, 04:34 PM   #13
joe_2000
Senior Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 1,013

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Hey Fu9ar, while I mostly agree with your point, I do think your wording is a bit harsh, and (according to my understanding) not in line with the LQ forum guidelines.
I did not perceive the OP's reaction as that moody, so let's just all step back and relax.

@like100ninjas: At this point I can see three options for you to solve your problem
- Use bash, try to fix your script as much as you can, and come back here for advice with the revised version of it when you are stuck. There are plenty of bash experts here who will be happy to help
- Wait for that zsh expert to see this thread, eventually
- Debug the script in zsh yourself by cutting it into little pieces. How can you make the script smaller and still reproduce the issue? If you can get it to be only one or two lines, and still fail, the problem will become more obvious.

My recommendation clearly is the first option, for reasons given in previous posts already.

Best of luck to you!
 
Old 12-15-2015, 10:39 PM   #14
like100ninjas
LQ Newbie
 
Registered: Apr 2015
Posts: 24

Original Poster
Rep: Reputation: Disabled
was taking a break from this to configure other stuff...

@grail: eh, i don't know. i've tried making that line a bunch of different things. i know that's not the solution.

@fu9ar: i don't know what your problem is, but you need to take it somewhere else. i get huffy because people vomit on my post and try to sound smart while doing it.

@habitual: thanks. read is a built-in shell command, though, and i think the wiki is referring to the library.

Last edited by like100ninjas; 12-15-2015 at 10:47 PM.
 
Old 12-16-2015, 02:55 AM   #15
fu9ar
Member
 
Registered: Oct 2014
Location: Cyberinternetspace
Distribution: Slackware, mostly
Posts: 49

Rep: Reputation: 2
The problem? You are arrogantly ignoring the advice given and vomiting a poorly written nonworking script and expecting people to read your mind about what the code is supposed to be doing.

What is the exit status of read -r line? Have you used help read to figure out what you are doing? Because from little that I can tell, this below is not what you are trying to do with it. What are you trying to do with it? Your incorrect and nonworking code also has no comments, so those of us reading it can't even begin to tell what you are trying to do! That's basic first year shit, man!


fu9ar@traveller:~$ help read
read: read [-ers] [-a array] [-d delim] [-i text] [-n nchars] [-N nchars] [-p prompt] [-t timeout] [-u fd] [name ...]
Read a line from the standard input and split it into fields.

Reads a single line from the standard input, or from file descriptor FD
if the -u option is supplied. The line is split into fields as with word
splitting, and the first word is assigned to the first NAME, the second
word to the second NAME, and so on, with any leftover words assigned to
the last NAME. Only the characters found in $IFS are recognized as word
delimiters.

If no NAMEs are supplied, the line read is stored in the REPLY variable.

Options:
(truncated output)

Last edited by fu9ar; 12-16-2015 at 03:00 AM.
 
  


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
LXer: Shell Scripting Part 3: Decision Control Structures in Shell Scripts LXer Syndicated Linux News 0 05-05-2015 10:01 PM
LXer: Shell Scripting Part 2: Accepting Inputs and Performing Shell Arithmetic LXer Syndicated Linux News 0 04-30-2015 07:10 AM
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 08:03 AM
win32,shell code,shell programming,shell scripting? mr.cracker Linux - Newbie 4 07-12-2013 11:20 PM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 04:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:41 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration