You are not logged in.

#1 2019-02-23 18:52:04

Mikeltxo15
Member
Registered: 2018-08-30
Posts: 10

[SOLVED] Script doesn't work, but the same command on a shell works

So, i was making a block for my i3blocks statusbar today. This particular one was for showing me the weather. Up to that point everything works fine, so then i decided i wanted a terminal to open with an expanded view of the weather forecast whenever i clicked on the block. Easy right?

But, when i told my term (st) to execute the command, it closed immediately after it exited. That's the default behavior, so no problem there. But st doesn't have a -hold flag, as xterm does. And adding "; $SHELL" at the end didn't work either. So after a lot of trial and error, i make an ugly mess of a command that actually does what i want!

$ st -e bash --rcfile <(echo "curl wttr.in")

Except that when i put it on a script, it exits with:

/home/user/scripts/spawn: line 2: syntax error near unexpected token `('
/home/user/scripts/spawn: line 2: `st -e bash --rcfile <(echo "curl wttr.in")'

The script is literally just the she-bang and the command. Why doesn't it work? Any solutions, or alternatives to the method i used?
The script:

#!/bin/sh
st -e bash --rcfile <(echo "curl wttr.in")

The block script:

#!/bin/sh
case $BLOCK_BUTTON in
        1) curl wttr.in/?format="%c+%t+%h" && st -e bash --rcfile <(echo "curl wttr.in") ;;
        *) curl wttr.in/?format="%c+%t+%h" ;;
esac

Thanks in advance! And yeah, I'm just starting on scripting, so maybe i did a noobie mistake.

Last edited by Mikeltxo15 (2019-02-24 00:41:28)

Offline

#2 2019-02-23 18:57:03

Mikeltxo15
Member
Registered: 2018-08-30
Posts: 10

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Okay, deleted the she-bang from the script, and now it works, it opens a new terminal with the forecast. But it's still not working on the block script :'(
Without the she-bang, it doesn't throw an error message, but clicking on the block does nothing, i think because it's not recognizing the CASE function.
With the she-bang, syntax error.
Even tried with the she-bang, but executing the command through another script without one, and again it doesn't exit with an error but clicking the block does nothing:
weather:

#!/bin/sh
case $BLOCK_BUTTON in
	1) curl wttr.in/?format="%c+%t+%h" && spawn ;;
	*) curl wttr.in/?format="%c+%t+%h" ;;
esac

spawn:

st -e bash --rcfile <(echo "curl wttr.in")

Last edited by Mikeltxo15 (2019-02-24 00:06:17)

Offline

#3 2019-02-23 19:38:48

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,042
Website

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Please use code tags when pasting to the boards: https://wiki.archlinux.org/index.php/Co … s_and_code

Where is $BLOCK_BUTTON defined?


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#4 2019-02-23 23:56:53

Mikeltxo15
Member
Registered: 2018-08-30
Posts: 10

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Sorry, it's been a while i posted anything, i forgot.
It's not, or at least not in the script. It refers to the mouse buttons where 1=left click, 2=middle click, 3=right click, and 4 and 5 are for the mouse wheel. Never had to define it, and i have others scripts with the same format and syntax and they work as expected.

Last edited by Mikeltxo15 (2019-02-24 00:02:04)

Offline

#5 2019-02-24 00:03:59

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 28,042
Website

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Edit your posts and fix them.

You can use `echo $BLOCK_BUTTON` in the script and set -x to debug.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#6 2019-02-24 00:18:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 22,143
Website

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Well, one problem is obvious: you are using a /bin/sh shebang but including a process substitution bashism in the script.  You must use /bin/bash as the shebang if you want to use process substitution.

But there really is no need for bash here:

st -e sh -c 'curl wttr.in; read'

(edit: s/command/process/g ... I'm forgetting the names of bashisms.  My recovery is progressing well.)

Last edited by Trilby (2019-02-24 00:38:44)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#7 2019-02-24 00:35:18

Mikeltxo15
Member
Registered: 2018-08-30
Posts: 10

Re: [SOLVED] Script doesn't work, but the same command on a shell works

Trilby wrote:

Well, one problem is obvious: you are using a /bin/sh shebang but including a command substitution bashism in the script.  You must use /bin/bash as the shebang if you want to use command substitution.

But there really is no need for bash here:

st -e sh -c 'curl wttr.in; read'

EUREKA!!!! Thank you so so much. Both of the things you said are absolutely correct.

#!/bin/bash
case $BLOCK_BUTTON in
	1) curl wttr.in/?format="%c+%t+%h" && st -e bash --rcfile <(echo "curl wttr.in") ;;
	*) curl wttr.in/?format="%c+%t+%h" ;;
esac
#!/bin/sh
case $BLOCK_BUTTON in
	1) curl wttr.in/?format="%c+%t+%h" && st -e sh -c 'curl wttr.in; read' ;;
	*) curl wttr.in/?format="%c+%t+%h" ;;
esac

Both of those scripts work now. I'm going with the second one, the one you suggested.
Marking the thread as solved

Offline

Board footer

Powered by FluxBB