LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 07-14-2010, 04:41 PM   #1
zagzagel
LQ Newbie
 
Registered: Jul 2010
Location: Portugal
Distribution: Ubuntu 10.04LTS
Posts: 21

Rep: Reputation: 1
bash -c not working with newlines


Hi everyone,

I've been using Linux for almost an year and I can't believe how I survived so long without knowing it (so far only used wind..ughh can't finish saying it).

Anyhow, I'm using Ubuntu 10.04LTS on Openbox. Everything is working fine, but when I add keybindings at some point I need globbing so I do <execute>bash -c "application /path/to/args/*"</execute> to enable globbing. This however has a problem, I can't add newlines between the arguments, and sometimes it leads to really long lines that have to be wrapped.

So, finally, my question: Is there anyway to execute an application through openbox's keybindings with globbing enabled which allows me to add newlines between the programs arguments?
[EDIT]I'd prefer not to make my own program to apply globbing to the application nor create scripts, so if that's the only way you can find to solve this problem then I do not need you answear (not trying to act up, it's just that I can solve it that way too, but prefer a more elegant aproach)[/EDIT]

Best regards,
Raimundo Martins

Last edited by zagzagel; 07-15-2010 at 12:41 PM.
 
Old 07-14-2010, 07:07 PM   #2
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 63
Interesting question. I don't use Ubunut but I do use openbox and I have tweaked the keybindings a bit. Can you give me an example of the sort of command that would need to be split over more than one line?
 
Old 07-14-2010, 07:39 PM   #3
zagzagel
LQ Newbie
 
Registered: Jul 2010
Location: Portugal
Distribution: Ubuntu 10.04LTS
Posts: 21

Original Poster
Rep: Reputation: 1
Well, I basically use these keybindings to play music so something like

<keybind key="backslash"><action name="Execute"><execute>audacious
~/music/mars\ volta\,\ the/2003\ -\ de-loused\ in\ the\ comatorium/inertiatic\ esp.mp3
~/music/mars\ volta\,\ the/2009\ -\ octahedron/*
~/music/prodigy\,\ the/*/*
</execute></action></keybind>

I don't actually have the really long lines right now because... well.. I'd have a really long config file (and it would be pointless to post dozens of lines when they're just paths to personal filenames) but it would be something like this.

I tried:

<keybind key="backslash"><action name="Execute"><execute>bash -c "audacious \
~/music/mars\ volta\,\ the/2003\ -\ de-loused\ in\ the\ comatorium/inertiatic\ esp.mp3 \
~/music/mars\ volta\,\ the/2009\ -\ octahedron/* \
~/music/prodigy\,\ the/*/*"
</execute></action></keybind>

But it doesn't work. It starts audacious without any song and I get an output like:
bash: line 1: ~/music/mars\ volta\,\ the/2003\ -\ de-loused\ in\ the\ comatorium/inertiatic\ esp.mp3: permission denied

I'm checking on openbox's source code to see if I can add something to the parser to understand my folders and automatically add keybinds to them. Fun project for holidays, uh? :P

Thanks for your interest =)
 
Old 07-15-2010, 11:21 AM   #4
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 63
Well if it was me I would just make an m3u playlist and set audacious as the default app to run the playlist, then when I click on the m3u playlist it would just work. However, as you want keybindings, not clicky clicky mouse clicking (I do understand), this works for me
Code:
    <keybind key="backslash">
      <action name="Execute">
        <execute>audacious \
        ~/save/share/music/Wilco\ \-\ Someone\ Else\'s\ Song.mp3
        ~/save/share/music/Thin\ Lizzy\ \-\ Borderline.m4a
        </execute>
      </action>
    </keybind>
 
Old 07-15-2010, 12:39 PM   #5
zagzagel
LQ Newbie
 
Registered: Jul 2010
Location: Portugal
Distribution: Ubuntu 10.04LTS
Posts: 21

Original Poster
Rep: Reputation: 1
Yes, that works for me too, but if you look closely you're not doing any globbing, ie you don't have something like:

Code:
audacious /play/everything/on/this/folder/*
But I see this is dragging along for too long, so I'll just call a C proggy to do the globbing instead of bash. And since bash calls ~/.bashrc on startup, it's probably most efficient this way. I'll post the C code of the program in case anyone stumbles upon this and needs my solution (still don't know what's wrong with bash and newlines which was the whole point of this question for me)

Code:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<glob.h> //Nice header :) allows  for filename expansion just like shell. Oh, how I love Linux! x)

//#define DEBUG

int main(int argc, char *argv[])
{
        int i = 0;
        glob_t globber;

        if(argc > 1)
        {
                glob(argv[1], GLOB_NOCHECK | GLOB_TILDE | GLOB_BRACE, NULL, &globber);
                for(i = 2; i < argc; i++)
                        glob(argv[i], GLOB_NOCHECK | GLOB_TILDE | GLOB_BRACE | GLOB_APPEND, NULL, &globber);
        }

#if DEBUG
        for(i = 0; i < globber.gl_pathc; i++)
                printf("Arg %d: %s\n", i, globber.gl_pathv[i]);
#endif

        execvp(globber.gl_pathv[0], globber.gl_pathv);
        fprintf(stderr, "Globber: failed to execute application: %s\n", globber.gl_pathv[0]);
        return 1;
}
The first argument is "audacious" in this case. So to keybind that folder I'd have something like:

Code:
<execute>
globber audacious
/play/everything/on/this/folder/*
/and/this/folder/too/*
/accepts/braces/{folder1,folder2}/{01,02,05}*
</execute>
It's actually not that bad now that I did that. Maybe the kernel should support globbing by itself? :P Or maybe it's just bloat for a kernel.

If anyone would be kind enough to explain me what's the problem in executing bash that way though, I'd still love to hear it.
 
  


Reply

Tags
bash, globbing


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Handling newlines in Bash MS3FGX Programming 7 09-10-2007 10:15 PM
Bash scripting question re: newlines retrovertigo Programming 4 07-06-2007 09:50 PM
Bash scripting question re: newlines retrovertigo Programming 1 07-06-2007 01:41 AM
Bash: Supress newlines with \c - Doesn't work stefanlasiewski Programming 5 07-26-2005 01:17 PM
Split a string on newlines (bash) rose_bud4201 Programming 7 04-14-2005 01:58 PM


All times are GMT -5. The time now is 12:38 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration