LinuxQuestions.org
Review your favorite Linux distribution.
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
  Search this Thread
Old 05-29-2008, 07:13 PM   #1
prol
Member
 
Registered: May 2008
Posts: 47

Rep: Reputation: 18
Running multiple commands in Konsole


Im trying to make a bash script that opens up a konsoe window and executes the cmmands in the script.However when I use the command konsole -e it allows me to enter only one command. how ca I make it run commands one after the other.
 
Old 05-29-2008, 07:33 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,845

Rep: Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006Reputation: 2006
Executing multiple commands in sequence
 
Old 05-29-2008, 08:08 PM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
Quote:
Originally Posted by David the H. View Post
The big problem is not concatenating commands, but dumping them into a newly created terminal emulator.

I usually do this (just a simple example):

Code:
urxvt -e bash -c "ls && sleep 10"
Feel free to use ||, && or ; depending on the effect you need to achieve in between the quotes. Also, in the example I use urxvt, but you can use konsole instead if you want. You will need to figure out the -e equivalent for konsole, I don't have it installed to check.

Last edited by i92guboj; 05-29-2008 at 08:09 PM.
 
Old 05-29-2008, 08:48 PM   #4
prol
Member
 
Registered: May 2008
Posts: 47

Original Poster
Rep: Reputation: 18
This is a the service menu I am trying to make:


[Desktop Entry]
Version=1.0
ServiceTypes=video/*
Actions=conv2mp3
X-KDE-Submenu=Convert Audio/Video

[Desktop Action conv2mp3]
Name=MP3
Exec=konsole -e "input_file='%f' && output_file_name=${input_file/.*/}&& ffmpeg -i '${input_file}' -acodec libmp3lame -ab 160k -ac 2 -ar 44100 '${output_file_name}.mp3'"


The && works in xterm but it doesnt recognize the %f and I thinks konsole recognizes it but cannot run multple commands
 
Old 05-29-2008, 09:00 PM   #5
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
Quote:
Originally Posted by prol View Post
This is a the service menu I am trying to make:


[Desktop Entry]
Version=1.0
ServiceTypes=video/*
Actions=conv2mp3
X-KDE-Submenu=Convert Audio/Video

[Desktop Action conv2mp3]
Name=MP3
Exec=konsole -e "input_file='%f' && output_file_name=${input_file/.*/}&& ffmpeg -i '${input_file}' -acodec libmp3lame -ab 160k -ac 2 -ar 44100 '${output_file_name}.mp3'"


The && works in xterm but it doesnt recognize the %f and I thinks konsole recognizes it but cannot run multple commands
Try to wrap it as I did above. Instead of directly launching the stuff, use konsole -e bash -c "commands". (though my guess is that this might not work either).

Your best bet to do this kind of stuff is to wrap everything into a shell script. Then, just call your shell script instead of concatenating so much commands.

Last edited by i92guboj; 05-29-2008 at 09:04 PM.
 
Old 05-29-2008, 09:10 PM   #6
prol
Member
 
Registered: May 2008
Posts: 47

Original Poster
Rep: Reputation: 18
Yes i tried it but it doesnt recognize the %f which is the file location of the selected file
 
Old 05-29-2008, 09:26 PM   #7
prol
Member
 
Registered: May 2008
Posts: 47

Original Poster
Rep: Reputation: 18
ok is there a way to run a command and show the output in a terminal
 
Old 05-29-2008, 09:32 PM   #8
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
Quote:
Originally Posted by prol View Post
ok is there a way to run a command and show the output in a terminal
Only by running into it.

I'd try something like this:

Code:
#!/bin/bash
input_file="$1"
output_file_name="${input_file/.*/}"
ffmpeg -i "${input_file}" -acodec libmp3lame -ab 160k \
    -ac 2 -ar 44100 "${output_file_name}.mp3"
read #this line wait for a return, you could use sleep
     #instead or something like that
Now, you need to save that script into a directory that's in your $PATH, and chmod u+x it.

On the desktop file you do:

Code:
[Desktop Entry]
Version=1.0
ServiceTypes=video/*
Actions=conv2mp3
X-KDE-Submenu=Convert Audio/Video

[Desktop Action conv2mp3]
Name=MP3
Exec=konsole -e "your-script.sh %f"
Note that I know very little about .desktop files so I don't know if the quotation has been done correctly (the bash script should be ok, though).
 
Old 05-29-2008, 10:12 PM   #9
prol
Member
 
Registered: May 2008
Posts: 47

Original Poster
Rep: Reputation: 18
Thank you so much.Solved my problem.ur the best.
 
Old 05-29-2008, 10:30 PM   #10
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 403Reputation: 403Reputation: 403Reputation: 403Reputation: 403
Quote:
Originally Posted by prol View Post
Thank you so much.Solved my problem.ur the best.
Glad it helped.

In case you are wondering, the key point when passing the argument is that kde pass arguments using %f, %u and things like those.

On the contrary, bash doesn't know about the nature of the arguments, and they are named by their position. On the kde land, we pass %f to our script, but once we are into the bash script, and since %f is the first parameter, we access this positional parameter as $1. That's the key, the rest is simple enough to understand if you made that long command line for the initial desktop file.
 
  


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
Konsole Commands List?? Mystical Itachi SUSE / openSUSE 2 10-16-2004 07:45 AM
Konsole commands vs Gui menu NKYG Linux - Software 2 06-24-2004 05:20 PM
Wireless commands for konsole otciii Linux - Wireless Networking 2 06-19-2004 05:57 PM
Executing commands in Konsole... meteotrade Linux - General 5 10-20-2003 07:34 PM
Konsole prompt/commands UB_KMA Linux - Newbie 4 07-12-2002 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:23 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