Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 terminal/shell doesnt work as expected. halp!, bash 101?

views
     
TSfailed.hashcheck
post Jul 13 2018, 05:35 PM, updated 6y ago

Neighborhood plant pathologist
*******
Senior Member
2,006 posts

Joined: Aug 2009
From: Shithole Klang
Edit: Answered: im noob.
brb commiting seppuku.
-----

ok so I have this media server that deal with CD image+cue
From time to time I need to convert it to flac, split, and sometimes further encode to opus.

the problem is on split part.


I use
CODE
for i in *.cue; do shnsplit -f "$i" -t %n-%t -o flac "${i%.*}.flac"; done
to read .cue and split the CD image accordingly.

To make it simpler and more 'modular', I attempt to put it in shell script in /bin, but it doesnt work.
tried to put it as .bashrc alias, also doesn't work.

when executed, the terminal just wait, you know, that kind of plain wait cursor as if something processing with output sent to /dev/null; except in this case there was nothing gets executed to begin with.
but when I directly input the command in prompt it work just fine.

The other two similar command to encode using ffmpeg and opusenc work just fine in shell script hmm.gif .

whats wrong eh?

edit:
using Debian stretch

This post has been edited by failed.hashcheck: Jul 13 2018, 09:20 PM
wKkaY
post Jul 13 2018, 06:49 PM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
First, run the shell script with "bash -x" to show the executed commands after string expansion. Is it executing what you expect?
TSfailed.hashcheck
post Jul 13 2018, 08:55 PM

Neighborhood plant pathologist
*******
Senior Member
2,006 posts

Joined: Aug 2009
From: Shithole Klang
QUOTE(wKkaY @ Jul 13 2018, 06:49 PM)
First, run the shell script with "bash -x" to show the executed commands after string expansion. Is it executing what you expect?
*
wow TIL there is this dank thing bash -x haha. neat.

start with what I have in directory, which is a flac CD image, and a corresponding .cue file.
CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# ls
Avril Lavigne - The Best Damn Thing.cue  Avril Lavigne - The Best Damn Thing.flac
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing#


with debug on, I run the command directly, which got parsed and executed as expected.
CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# for i in *.cue; do shnsplit -f "$i" -t %n-%t -o flac "${i%.*}.flac"; done
+ for i in *.cue
+ shnsplit -f 'Avril Lavigne - The Best Damn Thing.cue' -t %n-%t -o flac 'Avril Lavigne - The Best Damn Thing.flac'
shnsplit: warning: discarding initial zero-valued split point
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [01-Girlfriend.flac] (3:37.05) : 100% OK
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [02-I Can Do Better.flac] (3:17.07) :  88%
..
..
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing#


Now, I put the same command in executable file /bin/split
and run the file, the debug doesn't go further than just showing which file in /bin gets executed however.
Just that, no further output, no work done past this point.
CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# split
+ split



The similar file containing similar command to encode to opus, I put in /bin/convert
CODE
for i in *.*; do opusenc --vbr --bitrate 32 --comp 10 --expect-loss 0 "$i" "${i%.*}.opus"; done

work just fine. hmm.gif
CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# convert
+ convert
Encoding using libopus 1.2~alpha2 (audio)
-----------------------------------------------------
  Input: 44.1kHz 2 channels
 Output: 2 channels (2 coupled)
         20ms packets, 32kbit/sec VBR
Preskip: 312

[/] 13% 00:05:16.89 52.8x realtime, 30.65kbit/s^

wKkaY
post Jul 13 2018, 09:11 PM

misutā supākoru
Group Icon
VIP
6,008 posts

Joined: Jan 2003
From the shell, type "which split" and you'll find your answer...
TSfailed.hashcheck
post Jul 13 2018, 09:12 PM

Neighborhood plant pathologist
*******
Senior Member
2,006 posts

Joined: Aug 2009
From: Shithole Klang
Update:
I discoverd that the script can actually work if I supply the full path. ("/bin/split" instead of "split")

CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# /bin/split
+ /bin/split
shnsplit: warning: discarding initial zero-valued split point
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [01-Girlfriend.flac] (3:37.05) : 100% OK
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [02-I Can Do Better.flac] (3:17.07) : 100% OK
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [03-Runaway.flac] (3:48.43) :  48%..
..
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing#


But why the other script can work just fine without giving full path tho?
Aiyah. Even more confusing. Didn't know bash can be this hard doh.gif


I'm not going to bother fixing the actual cause, so here's little contraption to deal with this:
alias split='/bin/split' in .bashrc laugh.gif

and its finally worked.
CODE
root@kujira:~/downloads/Avril Lavigne - The Best Damn Thing# split
shnsplit: warning: discarding initial zero-valued split point
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [01-Girlfriend.flac] (3:37.05) : 100% OK
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [02-I Can Do Better.flac] (3:17.07) : 100% OK
Splitting [Avril Lavigne - The Best Damn Thing.flac] (40:37.50) --> [03-Runaway.flac] (3:48.43) :  40%

laugh.gif

TSfailed.hashcheck
post Jul 13 2018, 09:17 PM

Neighborhood plant pathologist
*******
Senior Member
2,006 posts

Joined: Aug 2009
From: Shithole Klang
QUOTE(wKkaY @ Jul 13 2018, 09:11 PM)
From the shell, type "which split" and you'll find your answer...
*
AAAAHHHHHHH!!!
LOL NOOB ME laugh.gif laugh.gif

of course there is existing binary /usr/bin/split right? right?
doh.gif

just.. just kill me.

 

Change to:
| Lo-Fi Version
0.0123sec    0.32    5 queries    GZIP Disabled
Time is now: 29th March 2024 - 08:20 AM